use of jakarta.persistence.PersistenceUnitUtil in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testIsLoaded.
public void testIsLoaded() {
EntityManagerFactory emf = getEntityManagerFactory();
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Employee emp = new Employee();
emp.setFirstName("Abe");
emp.setLastName("Jones");
Address addr = new Address();
addr.setCity("Palo Alto");
emp.setAddress(addr);
PhoneNumber pn = new PhoneNumber();
pn.setNumber("1234456");
pn.setType("Home");
emp.addPhoneNumber(pn);
pn.setOwner(emp);
em.persist(emp);
em.flush();
em.clear();
clearCache();
emp = em.find(Employee.class, emp.getId());
PersistenceUnitUtil util = emf.getPersistenceUnitUtil();
assertTrue("PersistenceUnitUtil says employee is not loaded when it is.", util.isLoaded(emp));
} finally {
rollbackTransaction(em);
}
}
use of jakarta.persistence.PersistenceUnitUtil in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testIsLoadedAttribute.
public void testIsLoadedAttribute() {
EntityManagerFactory emf = getEntityManagerFactory();
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Employee emp = new Employee();
emp.setFirstName("Abe");
emp.setLastName("Jones");
Address addr = new Address();
addr.setCity("Palo Alto");
emp.setAddress(addr);
PhoneNumber pn = new PhoneNumber();
pn.setNumber("1234456");
pn.setType("Home");
emp.addPhoneNumber(pn);
pn.setOwner(emp);
SmallProject project = new SmallProject();
project.setName("Utility Testing");
project.addTeamMember(emp);
emp.addProject(project);
em.persist(emp);
em.flush();
em.clear();
clearCache();
emp = em.find(Employee.class, emp.getId());
PersistenceUnitUtil util = emf.getPersistenceUnitUtil();
if (emp instanceof PersistenceWeaved) {
assertFalse("PersistenceUnitUtil says address is loaded when it is not", util.isLoaded(emp, "address"));
} else {
assertTrue("Non-weaved PersistenceUnitUtil says address is not loaded", util.isLoaded(emp, "address"));
}
assertFalse("PersistenceUnitUtil says projects is loaded when it is not", util.isLoaded(emp, "projects"));
emp.getPhoneNumbers().size();
assertTrue("PersistenceUnitUtil says phoneNumbers is not loaded when it is", util.isLoaded(emp, "phoneNumbers"));
assertTrue("PersistenceUnitUtil says firstName is not loaded when it is", util.isLoaded(emp, "firstName"));
} finally {
rollbackTransaction(em);
}
}
use of jakarta.persistence.PersistenceUnitUtil in project eclipselink by eclipse-ee4j.
the class EntityManagerJUnitTestSuite method testIsLoaded.
public void testIsLoaded() {
EntityManagerFactory emf = getEntityManagerFactory();
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Employee emp = new Employee();
emp.setFirstName("Abe");
emp.setLastName("Jones");
Address addr = new Address();
addr.setCity("Palo Alto");
emp.setAddress(addr);
PhoneNumber pn = new PhoneNumber();
pn.setNumber("1234456");
pn.setType("Home");
emp.addPhoneNumber(pn);
pn.setOwner(emp);
em.persist(emp);
em.flush();
em.clear();
clearCache();
emp = em.find(Employee.class, emp.getId());
PersistenceUnitUtil util = emf.getPersistenceUnitUtil();
assertTrue("PersistenceUnitUtil says employee is not loaded when it is.", util.isLoaded(emp));
} finally {
rollbackTransaction(em);
}
}
use of jakarta.persistence.PersistenceUnitUtil in project eclipselink by eclipse-ee4j.
the class EntityGraphTestSuite method testsubclassSubgraphs.
public void testsubclassSubgraphs() {
EntityManager em = createEntityManager();
EntityGraph<Project> employeeGraph = em.createEntityGraph(Project.class);
employeeGraph.addSubclassSubgraph(LargeProject.class).addAttributeNodes("budget");
employeeGraph.addAttributeNodes("description");
List<Project> result = em.createQuery("Select p from Project p where type(p) = LargeProject").setHint(QueryHints.JPA_FETCH_GRAPH, employeeGraph).getResultList();
PersistenceUnitUtil util = em.getEntityManagerFactory().getPersistenceUnitUtil();
for (Project project : result) {
assertFalse("Fetch Group was not applied", util.isLoaded(project, "name"));
assertTrue("Fetch Group was not applied", util.isLoaded(project, "description"));
assertTrue("Fetch Group was not applied", util.isLoaded(project, "budget"));
}
}
use of jakarta.persistence.PersistenceUnitUtil in project eclipselink by eclipse-ee4j.
the class EntityGraphTestSuite method testNestedEmbeddedFetchGroup.
public void testNestedEmbeddedFetchGroup() {
EntityManager em = createEntityManager();
EntityGraph<Runner> fetchGraph = em.createEntityGraph(Runner.class);
fetchGraph.addSubgraph("info").addSubgraph("status").addAttributeNodes("runningStatus");
Runner result = (Runner) em.createQuery("Select r from Runner r").setMaxResults(1).setHint(QueryHints.JPA_FETCH_GRAPH, fetchGraph).getResultList().get(0);
PersistenceUnitUtil util = em.getEntityManagerFactory().getPersistenceUnitUtil();
assertFalse("FetchGroup was not applied", util.isLoaded(result, "gender"));
assertFalse("FetchGroup was not applied", util.isLoaded(result.getInfo(), "health"));
assertTrue("FetchGroup was not applied", util.isLoaded(result.getInfo(), "status"));
assertTrue("FetchGroup was not applied", util.isLoaded(result.getInfo().getStatus(), "runningStatus"));
result.getInfo().getHealth();
assertTrue("FetchGroup was not applied", util.isLoaded(result.getInfo(), "status"));
assertTrue("FetchGroup was not applied", util.isLoaded(result, "gender"));
}
Aggregations