-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: hibernate does not resolve many-to-one-relation
PostPosted: Thu Jan 04, 2018 7:16 am 
Newbie

Joined: Tue Nov 28, 2017 9:42 am
Posts: 5
Hi,

I'm currently encountering the following problem:

I have a table with a foreign key e.g.: element *-----1 category ; an element has one category/a category can have many elements.

When I do a from element - HQL statement in the Hibernate Tools in Spring Tools Suite, I get all elements and also the categories. However, when I execute it via Java code the category-references do not get resolved (they are null).

Does anyone know how to solve this?

Thanks,

Regards

Klaus


Top
 Profile  
 
 Post subject: Re: hibernate does not resolve many-to-one-relation
PostPosted: Thu Jan 04, 2018 7:24 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
If you want to fetch them together, use a JOIN FETCH directive:

Code:
select c
from Category c
join fetch c.elements
where c.id = :id


Top
 Profile  
 
 Post subject: Re: hibernate does not resolve many-to-one-relation
PostPosted: Thu Jan 04, 2018 7:49 am 
Newbie

Joined: Tue Nov 28, 2017 9:42 am
Posts: 5
Thank you, it worked.

vlad wrote:
If you want to fetch them together, use a JOIN FETCH directive:

Code:
select c
from Category c
join fetch c.elements
where c.id = :id


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.