-->
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: @OneToOne producing eager fetching even though lazy is used!
PostPosted: Tue May 08, 2007 6:44 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
I don't understand why I'm getting eager fetching even though I've specified lazy fetching on a @OneToOne relationship, is this a bug?

My entities:

Code:
@Entity
@Table(name="tbl_user")
public class User implements Serializable
{
   @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
   private Integer id;
 
  @Column(nullable=false, length=100)
   private String username;
 
  @Column(nullable=false, length=100)
   private String password;
 
  @OneToOne(mappedBy="user", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
   private Customer customer;
............................
}

@Entity
@Table(name="tbl_customer")
public class Customer implements Serializable
{
   @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
   private Integer id;
 
  @Column(nullable=false, length=50)
   private String firstName;
 
  @Column(length=1)
   private String middleInitial;
 
  @Column(nullable=false, length=50)
   private String lastName;
 
  @Column(nullable=false, length=100)
   private String email;
 
  @Column(nullable=false, length=15)
   private String phone;
 
  @OneToOne(fetch=FetchType.LAZY)
   private User user;
.............................
}


My query in a SLSB:

Code:
public List<User> getAllUsers()
{
  return this.em.createQuery("select u from User u").getResultList();
}


The resulting generated queries:

Code:
Hibernate:
    /* select
        u
    from
        User u */ select
            user0_.id as id106_,
            user0_.active as active106_,
            user0_.password as password106_,
            user0_.userGroup_id as userGroup5_106_,
            user0_.username as username106_
        from
            tbl_user user0_
Hibernate:
    /* load com.agribeef.abcommerce.model.Customer */ select
        customer0_.id as id97_0_,
        customer0_.email as email97_0_,
        customer0_.firstName as firstName97_0_,
        customer0_.lastName as lastName97_0_,
        customer0_.middleInitial as middleIn5_97_0_,
        customer0_.phone as phone97_0_,
        customer0_.user_id as user7_97_0_
    from
        tbl_customer customer0_
    where
        customer0_.user_id=?
Hibernate:
    /* load com.agribeef.abcommerce.model.Customer */ select
        customer0_.id as id97_0_,
        customer0_.email as email97_0_,
        customer0_.firstName as firstName97_0_,
        customer0_.lastName as lastName97_0_,
        customer0_.middleInitial as middleIn5_97_0_,
        customer0_.phone as phone97_0_,
        customer0_.user_id as user7_97_0_
    from
        tbl_customer customer0_
    where
        customer0_.user_id=?
.........................................................


...and so on...for 315 queries! One Customer for each User, even though I didn't ask for it!

I'm using Hibernate 3.2.3, Annotations 3.3.0, EntityManager 3.3.1 - recreating this same problem in both JBoss and Glassfish.

Any ideas? Appreciate the help, thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 11:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/162.html

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 12:38 am 
Beginner
Beginner

Joined: Thu May 17, 2007 9:56 am
Posts: 21
Location: India
Can you try some thing like lazy="true" in your mapping file along with lazy fetch mode?It works fine to us. But we are using hibernate 3.

_________________
Kuzhali


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.