This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, I have solved it. Will post the fix tomorrow, hopefully, after testing.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,

 
Yup, yup, yup. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!