2017-03-15 87 views
0

我正在使用Hibernate Criteria从我的表中的列mobileno获取最大值。Hibernate(not JPA)Criteria - org.hibernate.QueryException:无法解析属性:

但是,当我得到的结果,它抛出一个异常

org.hibernate.QueryException: could not resolve property: mobileno of: 

我的表bean属性是:

@Column(name="id") 
private long id; 

@Column(name="code") 
private String code; 


@Column(name="mobileno") 
private String mobileno; 
//Setters and Getters 

Hibernate代码:

@Override 
public long getMaxMobileNo() { 
Session session = entityManager.unwrap(Session.class); 
Criteria criteria = session.createCriteria(Data.class);  
criteria.setProjection(Projections.max("mobileno"));   
return (long) criteria.uniqueResult(); 
} 

我在哪里出错了,我如何从我的表中获得最大值?

+1

“字符串”类型的“最大”? – nobeh

+0

@nobeh:是的。那就是问题所在? – user7646838

+0

Projections.max =属性最大值。非常重要的是,mobileno的最大价值是什么?我不知道预测,但似乎是数值。 – Nico

回答

0

它是一种解决办法,但你为什么不使用

Query query = session.createSQLQuery("SELECT MAX(column_name) FROM table_name"); 

每一个休眠版本将快速的方式。

相关问题