我遵循DAO方法:
@Override
public Company getCompanyById(Long companyId) {
Session session = sessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Company.class).add(
Restrictions.eq("companyId", companyId));
return (Company) criteria.uniqueResult();
}
我将2L传递给此功能。但是作为返回值获取null,尽管在数据库中存在具有以下id的条目。
同样在调试中我试着评估以下表达式:
sessionFactory.getCurrentSession().createSQLQuery("select * from Company")
结果:
SQLQueryImpl(select * from Company):
queryReturns = {java.util.ArrayList@7974} size = 0
querySpaces = null
callable = false
autodiscovertypes = false
queryString = {java.lang.String@7967}"select * from Company"
session = {org.hibernate.impl.SessionImpl@5735}"SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])"
parameterMetadata = {org.hibernate.engine.query.ParameterMetadata@7975}
values = {java.util.ArrayList@7976} size = 0
types = {java.util.ArrayList@7977} size = 0
namedParameters = {java.util.HashMap@7978} size = 0
namedParameterLists = {java.util.HashMap@7979} size = 0
optionalObject = null
optionalId = null
optionalEntityName = null
selection = {org.hibernate.engine.RowSelection@7980}
cacheable = false
cacheRegion = null
comment = {java.lang.String@7981}"dynamic native SQL query"
flushMode = null
cacheMode = null
sessionFlushMode = null
sessionCacheMode = null
collectionKey = null
readOnly = false
resultTransformer = null
看起来像空的结果。
尝试从数据库执行它:
请帮助找出错误。