How you can know if the persist method worked or not? I only can think in two solutions for this, but for sure there are some more direct or prepared for this. Anyway, I want to know if somebody knows problems with this solutions or ar better alternative?. Thanks?
When I use persist I don't have a return to check if the method finish successfull or not. (Maybe boolean or the entity itself to check the id)
UserEntity e = new UserEntity();
e.setName("Name");
e.setAge(30);
em.persist(e);
Option#1 EntityManger contains method http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManager.html#contains
UserEntity e = new UserEntity();
e.setName("Name");
e.setAge(30);
em.persist(e);
----
return em.contains(e);
Option#2 Return the entity ID
When I persist the entity, I can make commit
and return the entity or the Entity id, if I have an id, the persist method should be worked success.
UserEntity e = new UserEntity();
e.setName("Name");
e.setAge(30);
em.persist(e);
em.commit();
----
return e;//or return e.getId();