File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Persit method strange behaviour

 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this post is related with the :find and persist post
 
Ross Crockett
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic