This content has been marked as final.
Show 6 replies
-
1. Re: Entity Beans in 3.0 not persisting property changes
cyril.joui May 8, 2006 11:49 AM (in response to raygeeknyc)It's normal.
You have to call em.merge(b) after you made a modification.BeanType b = new BeanType(); b.setX(1); em.persist(b); b.setX(2); em.merge(b);
-
2. Re: Entity Beans in 3.0 not persisting property changes
raygeeknyc May 8, 2006 11:01 PM (in response to raygeeknyc)Thanks, I've seen that but based on my experience with other Persistence frameworks I expected the bean to be kept in sync with the database once it was persisted.
It seems that in EJB3.0 obtaining a bean from the database (via find) is not the same as introducing a bean to the database (via merge or persist) whereas in JDO and Hib3 I believe that the two were equivalent in this manner. -
3. Re: Entity Beans in 3.0 not persisting property changes
epbernard May 8, 2006 11:06 PM (in response to raygeeknyc)"raygeeknyc" wrote:
I have an entity bean that I am deploying in CR2, I am finding that the beans I instantiate via the EntityManager (ie a query returns them) are kept in sync with the database but when I create new instances outside of the persistence context and then use the Entity Manager persist (or merge) methods, they are added to the database but later changes to these beans' properties are not persisted.
for example
BeanType b = new BeanType();
b.setX(1);
em.persist(b);
b.setX(2);
After this the database contains 1 in the column mapped to by properrty X, whereas I expected it to contain 2
It should work. Remember that you must have a running db transaction though. -
4. Re: Entity Beans in 3.0 not persisting property changes
raygeeknyc May 9, 2006 12:06 PM (in response to raygeeknyc)Remember that you must have a running db transaction though.
Is this typically done through a wrapper method with the appropirate transaction attributes in such a case? I tried accessing the EntityManager's getTransaction() in my code and it [the call to getTransaction()] threw an EJBException. -
5. Re: Entity Beans in 3.0 not persisting property changes
epbernard May 10, 2006 12:17 AM (in response to raygeeknyc)yes this is done declaratively through @TransactionAttribute
-
6. Re: Entity Beans in 3.0 not persisting property changes
raygeeknyc May 11, 2006 11:21 PM (in response to raygeeknyc)Sure enough!
Thanks.