JPA(Toplink Essentials) using JTA on Glassfish: Issue In Loading References
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I think, I have solved it. Will post the fix tomorrow, hopefully, after testing.
Adeel Ansari
Ranch Hand
Posts: 2874
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
Perhaps turn logging on finest, or try to debug.
Adeel Ansari
Ranch Hand
Posts: 2874
posted 15 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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 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,
| Our first order of business must be this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |






