-->
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: FetchMode.JOIN not working with JPA
PostPosted: Sat Jun 23, 2012 8:51 pm 
Beginner
Beginner

Joined: Tue Oct 30, 2007 7:57 am
Posts: 47
I am using JPA with Hibernate 4.1.3. I noticed that when I annotate many-to-one relations to be eager "@ManyToOne(fetch=FetchType.EAGER)", the related entity is recovered in a second query, instead of creating a single query using a join.

To solve that, I decided to use @Fetch(FetchMode.JOIN), but it didn't work at all.

Code:
   @ManyToOne(fetch=FetchType.EAGER)
   @Fetch(FetchMode.JOIN)
   @JoinColumn(name="ID_TIPO_CONTRATO", insertable=true, updatable=false, nullable=false)
   private TipoContrato tipoContrato;   


The only way to force a join seems to be writing a query with a "left join fetch" to the related entity. Doing that, the main entity and the related one are recovered in a single query

Code:
"select cj " +
"from ContratoJoin cj " +
"left join fetch cj.tipoContrato tc "


Does @Fetch work with JPA or only in pure Hibernate?


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.