2
我有以下@OneToOne
關係:OneToOne懶惰總是取孩子
@Entity
@Table(name="USER")
public class User implements Serializable{
private Basket basket;
@OneToOne(cascade = CascadeType.ALL,orphanRemoval=true,mappedBy="user", fetch=FetchType.LAZY)
public Basket getBasket() {
return basket;
}
public void setBasket(Basket basket) {
this.basket = basket;
}
//all other proerties are ommited and none relevant.
}
現在籃類:
@Entity
@Table(name="BASKET")
public class Basket implements Serializable {
private User user;
@OneToOne(fetch=FetchType.LAZY)
public User getUser() {
return user;
}
//all other proerties are ommited and none relevant.
}
現在我想要在其中有春天對象使用HQL來獲取用戶對象使用AOP的交易管理器:
public User getUser(String param1,String param2) {
Session session = this.sessionfactory.getCurrentSession();
String queryString = "from objects.User user where user.param1=:param1 and user.param2=:param2";
Query query = session.createQuery(queryString);
query.setString("param1", param1);
query.setString("param2", param2);
User user = (User) query.uniqueResult();
return user;
}
但我看到Basket也被提取althoug h它是懶惰的:
Hibernate: select user0......
Hibernate: select basket0.....
爲什麼?
你可以發佈第二個SELECT的整個查詢嗎? –