-->
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.  [ 1 post ] 
Author Message
 Post subject: how to prevent n + 1 fetch in native query?
PostPosted: Tue Oct 27, 2009 12:49 pm 
Newbie

Joined: Tue Oct 27, 2009 12:25 pm
Posts: 1
Hi all,

I need some help for a native query in JPA using Hibernate.

I have a JPA query as follows:

Code:
entityManager.createQuery("from myTableA a JOIN FETCH myTableB");


Hibernate generates exactly ONE SQL statement out of the query as expected.

When I use a native query as

Code:
entityManager.createNativeQuery("select * from MY_TABLE_A a JOIN MY_TABLE_B b ON a.fk_id = b.id", MyTableA.class);


Hibernate generates the query above and n queries for the related table MY_TABLE_B although it is joined.

Do I have any possibility to prevent hibernate from doing the n additional queries which should normally be useless?

Thanks in advance,
Pascal


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

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.