hibernate报错

本文探讨了在使用Hibernate框架进行数据库查询时遇到的一个具体问题:当尝试使用isNotEmpty与isNotNull条件时引发的MappingException异常。通过调整查询条件为不等于0且非空,成功解决了异常并确保了查询的有效性。

List jobCri= session.createCriteria(JobTransportList.class)
   .setProjection(

Projections.distinct(

Property.forName  (JobTransportList._OrderID)))  

.add(

Restrictions.and(

   Property.forName(JobTransportList._OrderID).isNotEmpty(),
   Property.forName(JobTransportList._OrderID).isNotNull())


.list();

因为查询语句中没有使用到OrderID,所以如果使用到isNotEmpty,isNotNull

就会报如下错误,改成

  .add(Restrictions.and(Property.forName(JobTransportList._OrderID).ne(new BigDecimal(0)),
         Property.forName(JobTransportList._OrderID).isNotNull())) 
即没此问题了

org.hibernate.MappingException: Property path [pglms.j2ee.domain.tms.JobTransportList.OrderID] does not reference a collection
 at org.hibernate.criterion.AbstractEmptinessExpression.getQueryableCollection(AbstractEmptinessExpression.java:61)
 at org.hibernate.criterion.AbstractEmptinessExpression.toSqlString(AbstractEmptinessExpression.java:40)
 at org.hibernate.criterion.LogicalExpression.toSqlString(LogicalExpression.java:39)
 at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:333)
 at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:71)
 at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
 at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1532)
 at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
 at pglms.j2ee.service.tms.CalControlCostTest.testJob(CalControlCostTest.java:36)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at junit.framework.TestCase.runTest(TestCase.java:154)
 at junit.framework.TestCase.runBare(TestCase.java:127)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:118)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

 

评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值