1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
public boolean create(Event anEvent){
EntityManagerFactory factory = Persistence.createEntityManagerFactory("mdc1");
EntityManager manager = factory.createEntityManager();
EntityTransaction transaction = manager.getTransaction();
transaction.begin();
manager.persist(anEvent);
transaction.commit();
manager.close();
factory.close();
return true;
}
public Event read(Integer id){
EntityManagerFactory factory = Persistence.createEntityManagerFactory("mdc1");
EntityManager manager = factory.createEntityManager();
EntityTransaction transaction = manager.getTransaction();
transaction.begin();
Event anEvent = manager.find(Event.class, id);
transaction.commit();
manager.close();
factory.close();
return anEvent;
} |
Partager