-->
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.  [ 2 posts ] 
Author Message
 Post subject: Why is FetchMode.JOIN ignored?
PostPosted: Wed Aug 11, 2010 12:56 pm 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Hi,

I have a Flight and a Pilot Entity. I would like Hibernate to load the Pilot relationship eager using a JOIN,
however executing "select f from flight f order by f.id" I see one select for each Pilot returned by the query.

Any idea what the reason could be?

Thank you in advance, Clemens

Code:

@Entity
@SequenceGenerator(name="flight_seq", sequenceName="flight_id_seq", allocationSize=1)
public class Flight {
    @Id
    @Column(columnDefinition = "SERIAL")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="flight_seq")
    public Integer id;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name="pilotid", nullable=true, columnDefinition="INTEGER")
    @Fetch(org.hibernate.annotations.FetchMode.JOIN)
    Pilot pilot;
}

@Entity
@SequenceGenerator(name="pilot_seq", sequenceName="pilot_id_seq", allocationSize=1)
public class Pilot {
    @Id
    @Column(columnDefinition = "SERIAL")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="pilot_seq")
    public Integer id;
}


Top
 Profile  
 
 Post subject: Re: Why is FetchMode.JOIN ignored?
PostPosted: Wed Aug 11, 2010 1:24 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
That is the expected behavior since HQL queries (in most cases) doesn't use the the fetch settings defined in the class. You'll need to re-write your HQL to something like:
Code:
select f from flight f left join f.pilot order by f.id


http://docs.jboss.org/hibernate/stable/ ... ing-custom


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