-
1. Re: Fundamental question about em.persist
vanyatka Dec 13, 2007 9:58 AM (in response to vanyatka)I have to come back to this issue once again. There must be some easy explanation.
The following code produces "Test Card" in the DB. Why the last change doesn't get persisted? It is a part of the transaction, after all.@Create @Transactional public void init() { Card card = new Card(); card.setName("Test Card"); entityManager.persist(card); card.setName("The final name"); }
-
2. Re: Fundamental question about em.persist
junkie Dec 13, 2007 1:30 PM (in response to vanyatka)I always managed to avoid entity updates after a persist in the same method call... however what happens if you add
card = entityManager.merge(card);
directly after the persist call? -
3. Re: Fundamental question about em.persist
vanyatka Dec 13, 2007 1:51 PM (in response to vanyatka)"JUnkie" wrote:
I always managed to avoid entity updates after a persist in the same method call...
May I ask why? By itself persist() doesn't necessarily triggers DB call, just introduces the object to the persistence context. If I make an update later, should be fine, the important thing is that all changes are flushed before the transaction commits.
however what happens if you add
card = entityManager.merge(card);
directly after the persist call?
Nothing changes. The same "old" record in the DB.
Now again, after persist() finishes the object is already in the persistent context, unless it is wrapped in some sort of dynamic proxy object which is later saved into the DB instead of the original object.
However I don't recall anything anywhere that would mention calling persist() the last method in your transaction, so to avoid changes between persist() and transaction commit. -
4. Re: Fundamental question about em.persist
vanyatka Dec 13, 2007 2:06 PM (in response to vanyatka)Black magic, it works now, even without merge!!!! :)
matt.drees gave me a hint how to @Startup application scoped components properly and it works now
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4112676#4112676
The only change I made is that now the component starts up with @Startup, and when I reported I referenced it from some page so it would start up.
So far I don't get what happened. -
5. Re: Fundamental question about em.persist
pmuir Dec 14, 2007 11:06 AM (in response to vanyatka)What sort of persistence context are you using?
-
6. Re: Fundamental question about em.persist
vanyatka Dec 14, 2007 1:20 PM (in response to vanyatka)"pete.muir@jboss.org" wrote:
What sort of persistence context are you using?
Standard out-of-the-box conversation-scoped SMPC injected with @In.