Commit e9a3f138 by Patryk Czarnik

Program czytający Employee wg id

parent 08b4106f
package programy;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import model.Employee;
public class P01_OdczytajWgId {
public static void main(String[] args) {
System.out.println("Startujemy...");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("hr_postgresql");
EntityManager em = emf.createEntityManager();
System.out.println("Mam EntityManagera: " + em);
Integer id = 103;
Employee emp = em.find(Employee.class, id);
System.out.println("Odczytany obiekt: " + emp);
if(emp != null) {
System.out.printf("%s %s (%s) zarabia %s\n",
emp.getFirstName(), emp.getLastName(), emp.getJob().getJobTitle(), emp.getSalary());
}
em.close();
emf.close();
System.out.println("Koniec");
}
}
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"> <persistence version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
<persistence-unit name="alx_mszczonow_2" transaction-type="RESOURCE_LOCAL"> <persistence-unit name="hr_postgresql" transaction-type="RESOURCE_LOCAL">
<class>model.Country</class> <class>model.Country</class>
<class>model.Department</class> <class>model.Department</class>
<class>model.Employee</class> <class>model.Employee</class>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment