-->
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.  [ 8 posts ] 
Author Message
 Post subject: JPA native entity queries eager fetch
PostPosted: Tue Jun 13, 2017 10:10 am 
Newbie

Joined: Fri Aug 01, 2014 5:54 am
Posts: 13
Location: Brazil
The documentation says:

Quote:
It is possible to eagerly join the Phone and the Person entities to avoid the possible extra roundtrip for initializing the many-to-one association.
Example 475. JPA native query selecting entities with joined many-to-one association


Code:
List<Phone> phones = entityManager.createNativeQuery(
    "SELECT * " +
    "FROM Phone ph " +
    "JOIN Person pr ON ph.person_id = pr.id", Phone.class )
.getResultList();

for(Phone phone : phones) {
    Person person = phone.getPerson();
}


I have a very similar case but when I do the equivalent to this:
Code:
for(Phone phone : phones) {
    Person person = phone.getPerson();
}


Hibernate sends new queries to every Person I try to get from a phone.


Top
 Profile  
 
 Post subject: Re: JPA native entity queries eager fetch
PostPosted: Tue Jun 13, 2017 12:06 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You should open a Jira issue for that.

Meanwhile, try this example in the User Guide.


Top
 Profile  
 
 Post subject: Re: JPA native entity queries eager fetch
PostPosted: Tue Jun 13, 2017 12:35 pm 
Newbie

Joined: Fri Aug 01, 2014 5:54 am
Posts: 13
Location: Brazil
After changing my code to look like example 477 I get a list of Persons, not Phones.

Last time I tried to report a bug on Jira they asked for a running example. I tried to follow a guide on how to create the example but couldn't.


Top
 Profile  
 
 Post subject: Re: JPA native entity queries eager fetch
PostPosted: Tue Jun 13, 2017 4:29 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
It's very simple. Just download the template and follow the steps in that article.


Top
 Profile  
 
 Post subject: Re: JPA native entity queries eager fetch
PostPosted: Wed Jun 14, 2017 9:34 am 
Newbie

Joined: Fri Aug 01, 2014 5:54 am
Posts: 13
Location: Brazil
Could you point the article? Or put a link to it in README.md?


Top
 Profile  
 
 Post subject: Re: JPA native entity queries eager fetch
PostPosted: Thu Jun 15, 2017 3:30 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Here's the link

http://in.relation.to/2016/01/14/hibern ... -template/

For Readme file, send us a Pull Request.


Top
 Profile  
 
 Post subject: Re: JPA native entity queries eager fetch
PostPosted: Tue Jun 20, 2017 11:32 am 
Newbie

Joined: Fri Aug 01, 2014 5:54 am
Posts: 13
Location: Brazil
https://hibernate.atlassian.net/browse/HHH-11827

https://github.com/hibernate/hibernate-test-case-templates/issues/20


Top
 Profile  
 
 Post subject: Re: JPA native entity queries eager fetch
PostPosted: Tue Jun 20, 2017 2:53 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Thanks. As explained by Steve in the Jira issue, the docs will need to be updated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.