aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Persit method strange behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Persit method strange behaviour" Watch "Persit method strange behaviour" New topic
Author

Persit method strange behaviour

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

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


SCJP, SCJD, SCWCD, OCPJBCD
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

this post is related with the :find and persist post
Ross Crockett
Ranch Hand

Joined: Aug 25, 2009
Posts: 30
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

Joined: Sep 18, 2003
Posts: 916

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Persit method strange behaviour