File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes JPA(Toplink Essentials) using JTA on Glassfish: Issue In Loading References Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA(Toplink Essentials) using JTA on Glassfish: Issue In Loading References" Watch "JPA(Toplink Essentials) using JTA on Glassfish: Issue In Loading References" New topic
Author

JPA(Toplink Essentials) using JTA on Glassfish: Issue In Loading References

Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Consider this log.


Now, the first query, stated in the log, is giving me 5 records.


And for some stupid reason its not retrieving anything with the second query in the log when its binding value, `3bdac813d6034a26b336804794fb667f`. I expect one record, of course. For other 4 values I am getting things perfectly fine, just not getting for the first one. I omitted the log for other values, by the way. And yes, its not particularly happens to the first record always. The behaviour is arbitrary sometimes happens, sometimes not, and could happen to any record.

To make it clear explicitly, the first query is `FOR UPDATE`, all others are just loading relations.

Now the code snippet.


In the code, I am trying to load references eagerly. Didn't put the `fetchType=FETCH_TYPE.EAGER` attribute, because don't always want that kinda behaviour. But in this case I need that, so doing it manually.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I think, I have solved it. Will post the fix tomorrow, hopefully, after testing.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I think no I didn't find anything. By some reason its not loading OneToOne, and a ManyToOne relationship for one of the object. That I expect it to load eagerly.
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Are you sure the data is in the database? Ty executing the SQL directly through JDBC, do you get the expected result?

Perhaps turn logging on finest, or try to debug.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Thanks James, for your input.

I just finished up fixing this. Actually, I noticed the data which existed before I start my Glassfish, doesn't have any issue in loading. But when I persist some fresh entities, and try to load that along with all its eager fetch associations. The associations were being picked up from cache, I believe. Because problem doesn't persist after I restart the Glassfish, and invoke my bean. For fresh entities its always the same, not getting loaded.

Since, my actual query is FOR UPDATE, that really picks all the records from database, but its associations are get loaded from cache if found. So, I tried to use TopLinkQueryHints.REFRESH=true, and TopLinkQueryHints.REFRESH_CASCADE=CascadePolicy.CascadeAllParts. That didn't work, no idea why. It should, IMO.

Now the fix. I manually called `em.referesh()` on that particular entity, which was being picked up from cache. That solved my issue. Below is the modified method,

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA(Toplink Essentials) using JTA on Glassfish: Issue In Loading References
 
Similar Threads
EAR deplyment error in glassfish
the hello-jaxws sample
Bug in the installation java_ee_sdk-5_05 on Windows Vista
JWSDP2.0 - problem in deploying hello-jaxws sample application
Apache Derby Sql Statement's