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.