我正在使用 hibernate 从 MySQL 数据库中检索数据。
@Transactional
public List<PendingDomainEntity> listPendingDomain(int count, int offset)
throws DaoException {
try {
Criteria listCriteria = sessionFactory.getCurrentSession().createCriteria(PendingDomainEntity.class);
listCriteria.addOrder(Order.asc("domaincreateddt"));
listCriteria.setMaxResults(count);
listCriteria.setFirstResult(offset);
Criterion domainstatus = Restrictions.eq("domainstatus", "Pending").ignoreCase();
listCriteria.add(domainstatus);
@SuppressWarnings("unchecked")
List<PendingDomainEntity> pendingDomainList = (List<PendingDomainEntity>) listCriteria.list();
LOGGER.debug("Regg-Service: The pending domain list is:={}", pendingDomainList);
return pendingDomainList;
} catch (Exception ex) {
LOGGER.error("Exception: Service: Error while retrieving the pending domains list");
throw new DaoException(ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
}
}
这是在 PendingDomainEntity 类中声明 domainCreatedDt 的方式
@Column(name = "DOMAINCREATEDDT")
private Timestamp domainCreatedDt;
我收到以下异常消息
could not resolve property: domaincreateddt of: mypackage.DTO.PendingDomainEntity
但是当我为 Order 使用不同的列名时,它工作正常。对时间戳列的排序有任何限制吗?
最佳答案
查看关于 HQL 的文档章节(同样适用于 Criteria API):
16.1. Case Sensitivity
With the exception of names of Java classes and properties, queries are case-insensitive. So SeLeCT is the same as sELEct is the same as SELECT, but org.hibernate.eg.FOO is not org.hibernate.eg.Foo, and foo.barSet is not foo.BARSET....
这是 JAVA 名称:
private Timestamp domainCreatedDt;
这意味着,这不是一样的:
listCriteria.addOrder(Order.asc("domaincreateddt"));
简单地说,它必须是 domainCreatedDt
关于java - 带有 hibernate 条件 API 的 MySQL 中的 Orderby Timestamp 列抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27830039/