我有这种类型的查询
Critetria criteria = session.createCriteria(Perosn.class,"person");
criteria.createAlias("person.cityInformation","city",JoinType.LEFT_OUTER_JOIN);
criteria.createAlias("city.streetInformation","street",JoinType.LEFT_OUTER_JOIN);
criteria.add(new NativeSQLOrder("field({alias}.id,3,2,1)",true)));
NativeSQLOrder.java
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.annotations.common.util.StringHelper;
import org.hibernate.criterion.CriteriaQuery;
import org.hibernate.criterion.Order;
public class NativeSQLOrder extends Order
{
private static final long serialVersionUID = 1L;
private final static String PROPERTY_NAME = "uselessAnyways";
private boolean ascending;
private String sql;
protected NativeSQLOrder(String sql, boolean ascending)
{
super(PROPERTY_NAME, ascending);
this.sql = sql;
this.ascending = ascending;
}
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException
{
StringBuilder fragment = new StringBuilder();
fragment.append("(");
fragment.append(sql);
fragment.append(")");
fragment.append(ascending ? " asc" : " desc");
return StringHelper.replace(sql, "{alias}", criteriaQuery.getSQLAlias(criteria));
}
}
我想通过街道字段的ID订购但是使用这个我得到第一个表人的别名。是否有任何方式我将得到别名的街道表
答案 0 :(得分:0)