我们在尝试将hibernate从3.5.6迁移到3.6.10时遇到问题。我们正在使用hbm.xml配置文件。以下是标准:
public List<Cat> findCats(Com com) {
DetachedCriteria criteria = DetachedCriteria.forClass(Occupe.class);
criteria.add(Restrictions.eq("com", com));
criteria.add(Restrictions.or(Restrictions.isNull("datLibPt"),
Restrictions.gt("datLibPt", Calendar.getInstance().getTime())));
criteria.add(Restrictions.isNull("delDate"));
criteria.createAlias("cat", "cat");
criteria.add(Restrictions.isNull("cat.delDate"));
criteria.addOrder(Order.asc("cat.csv"));
criteria.setProjection(Projections.property("cat"));
return findByCriteria(criteria);
}
使用Hibernate 3.5.6,它会生成以下查询:
Hibernate: select this_.TRA_ID as y0_ from mydb..OCCUPE this_
inner join mydb..CAT cat1_ on this_.TRA_ID=cat1_.TRA_ID where this_.COM_ID=? and (this_.OCC_DAT_LIB_FCT is null or this_.OCC_DAT_LIB_FCT>?) and this_.DELDATE is null and cat1_.DELDATE is null order by cat1_.TRA_CSV asc
使用Hibernate 3.6.10,它会生成以下查询:
select this_.TRA_ID as y0_ from mydb..OCCUPE this_
inner join mydb..CAT cat1_ on this_.TRA_ID=cat1_.TRA_ID
inner join mydb..CAT cat1_ on this_.TRA_ID=cat1_.TRA_ID where this_.COM_ID=? and (this_.OCC_DAT_LIB_FCT is null or this_.OCC_DAT_LIB_FCT>?) and this_.DELDATE is null and cat1_.DELDATE is null order by cat1_.TRA_CSV asc
由于(逻辑)错误com.sybase.jdbc3.jdbc.SybSQLException: Tables 'mydb..CAT' and 'mydb..CAT' have same exposed names.
除了重复的内部连接语句之外,3.6.10查询与3.5.6查询严格相似。我试图理解这种奇怪的行为。我想我将使用HQL请求,但如果您有任何提示,请不要犹豫,评论;)