Close

JPA - Persistence Examples

Code Snippets JPA JAVA EE 

    public static void main(String[] args) {
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("example-unit");
try {
persistEntity(emf);
runNativeQueries(emf);
loadEntity(emf);
} finally {
emf.close();
}
}




    public static void main(String[] args) {
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("example-unit");
try {
persistEntities(emf);
displayEntities(emf);
} finally {
emf.close();
}
}
Original Post




    static void printLoadState(String msg, Employee employee) {
System.out.printf("-- %s --%n", msg);
PersistenceUtil pu = Persistence.getPersistenceUtil();
boolean employeeLoaded = pu.isLoaded(employee);
System.out.printf("employee loaded: %s%n", employeeLoaded);
boolean phonesLoaded = pu.isLoaded(employee, "phones");
System.out.printf(" phones loaded: %s%n", phonesLoaded);
System.out.println("---------------");
}
Original Post




See Also