• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Persit method strange behaviour

 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I do some experiments with Glassfish and Postgres, lets consider the next code snippet :


the theory sustains that an entity can become managed by using the perist method. If is managed it content will be synchronized with the database when the transaction ends or when the corresponding query is used. In the previous code snippet the method doStuff get it own transaction, this transaction end once with the method, that means the entity content must by synchronized with the database.
Well, I just try this and this it seams to be wrong. To get the changes in the database I need extra to trigger the flush method.
My question is why do I need to call flush ?

Regards,
Mihai
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this post is related with the :find and persist post
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On line 5 in your code you have the TransactionAttributeType as REQUIRED_NEW, I think the value your looking for is REQUIRES_NEW. I'm not sure if that would mess with the compilation of your code or not, but if it's running, your transaction could be defaulting to REQUIRED if the dodgy annotation is ignored (I'm not 100% sure what happens in that scenario).

If that's the case, and your doStuff() method is called from an existing transaction (e.g. called from another EJB bean), then is it possible your entity won't be persisted until the enclosing transaction commits?

That sound logical to anyone?

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ross

Yes you are right I type the code snippet and I don't have a checker for the java syntax, the REQUIRED_NEW is REQUIRES_NEW.
Please see the find and persist in the same transaction post, this post describes the problem better.

Regards,
Mihai
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic