populating @OneToOne from query
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Try executing the query within a transaction, or you must use a fetch join with the AttachmentInfo relationship.
Kind regards
Cesar
When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
It does work on the production server (just not the test one) so I wonder if something odd is going on there. I tried the fetch join and it didn't return null. But it also didn't behave as expected. The data looks fine on test, but now I wonder if there is something subtle going on...
In general should the fetch join be required if I have fetch set on the field?
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
The answer is no, if the relationship is a single value the default fetch type is eager.In general should the fetch join be required if I have fetch set on the field?
I have two observations, first is about the query the postId attribute doesn't exist in the entity Attachment, and the other is about the way you mapping the relationship:
Kind regards
Cesar
When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Cesar Loachamin wrote:Hi Jeanne
I have two observations, first is about the query the postId attribute doesn't exist in the entity Attachment, and the other is about the way you mapping the relationship:
postId does exist on Attachment. I omitted it when posting because it was an extraneous detail. I wanted less code so the relationship parts would be more obvious. I'm not clear what your observation is on the relationship
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Kind Regards
When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
So I decided to dig a bit more into the test server instance and see the difference. While doing so I enabled the logging of SQLs generated by Hibernate and turns out the SQL being generated is incorrect (on all instances - local, test and production):
Notice the join clause (attachment0_.attach_id=attachment1_.attach_desc_id) - it's completely wrong. The reason why this works locally and in production is just by chance since the keys generated for both those tables are identical. So locally and in production the attach_id matches the attach_desc_id in the other table. Unlike in test server instance where those ids are different.
I looked around some documentation and the mapping to understand why that incorrect join clause is being generated. Thanks to James' and Cameron's answers here, I was able to fix the JPA mapping on those classes. So now those classes have been fixed to:
and Hibernate now generates the correct query:
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
| If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











