【发布时间】:2017-06-17 23:26:27
【问题描述】:
我有这两个实体:
@Entity
@Table(name = "BA_USER", schema = "MYSCHEMA")
@XmlType(namespace = BusinessOperations.NAMESPACE)
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserWeb implements Serializable, UserDetails, SecurityUserInfo, Auditable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "userGenerator")
@SequenceGenerator(name="userGenerator", sequenceName="SEQ_USER")
@Column(name = "USERID", unique = true, nullable = false, precision = 22, scale = 0)
private long userid;
@ManyToOne(targetEntity = Country.class, fetch = FetchType.LAZY)
@JoinColumn(name = "COUNTRYID")
private Country country;
@ManyToOne(targetEntity = Menu.class, fetch = FetchType.LAZY)
@JoinColumn(name = "MENUID")
private Menu menu;
//Getters and Setters
}
和
@Entity
@Table(name = "BA_PREMIUMUSER", schema = "MYSCHEMA")
public class PremiumUser implements java.io.Serializable {
@Id
@OneToOne(targetEntity = UserWeb.class, fetch = FetchType.LAZY)
@JoinColumn(name = "USERID")
private UserWeb userWeb;
@ManyToOne(targetEntity = Customer.class, fetch = FetchType.LAZY)
private Customer customer;
//Getters and Setters
}
然后,在我的 DAO 中,我有以下方法:
public List<PremiumUser> findAllUsers(Long userid, Long customerId, Menu menu) {
Criteria criteria = getSession().createCriteria(PremiumUser.class);
criteria.add(Restrictions.eq("clienteProsegur", customerId));
criteria.createAlias("userWeb", "userweb", CriteriaSpecification.INNER_JOIN);
criteria.add(Restrictions.eq("userweb.menu", menu));
return criteria.list();
}
Hibernate 正在创建以下查询:
select this_.USERID as USERID52_0_, this_.CUSTOMER as CUSTOMER2_52_0_
from MYSCHEMA.BA_PREMIUMUSER this_
where userweb1_.MENUID=2 and this_.CUSTOMERID=3
我希望 createAlias 方法在查询中创建一个连接语句,像这样_
select this_.USERID as USERID52_0_, this_.CUSTOMER as CUSTOMER2_52_0_
from MYSCHEMA.BA_PREMIUMUSER this_
inner join MYSCHEMA.BA_USER userweb1_ on this_.USERID = userweb1.USERID
where userweb1_.MENUID=2 and this_.CUSTOMERID=3
我正在使用这个版本的休眠:Hibernate-core-3.6.0.Final
我想我在这里遗漏了一些东西。
【问题讨论】:
标签: java hibernate hibernate-criteria