我有收费的用户实体。提到下面
@Entity
@Table(name="user")
public class User { ...
@OneToMany(mappedBy="user",fetch=FetchType.LAZY)
private Set<Fees> fees = new HashSet<Fees>();
使用下面提到的方法hibernate获取带有id的用户同时获取费用
@Transactional(readOnly=true)
public User getUserById(Long id) {
return (User)sessionFactory.getCurrentSession().get(User.class, id);
}
我的理解是hibernate不应该获取费用对象但它会这样做。日志打印费也选择。
Hibernate:选择fees0_.user_id为user3_8_1_,fees0_.fees_id为fee1_1_,fees0_.fees_id为fees1_5_0_,fees0_.amount为amount5_0_,fees0_.user_id为user3_5_0_来自费用fee0_ where fees0_.user_id =?