CriteriaBuilder等运算符不起作用

时间:2015-01-09 17:28:37

标签: jpa eclipselink

我是JPA的新手。我正在使用Eclipse JDBC 2.5.2对Oracle数据库和Oracle JDBC驱动程序。对于下面的简单代码:

public List<DummyGrp> findByProperty(String propertyName, Object value) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery<DummyGrp> cq = cb.createQuery(DummyGrp.class);
    Root<DummyGrp> rootQuery = cq.from(DummyGrp.class);
    cq.select(rootQuery);
    cq.where(cb.equal(rootQuery.get(propertyName),value));
    TypedQuery<DummyGrp> q = entityManager.createQuery(cq);
    return q.getResultList();

}

结果始终为空。打开调试后,我确实看到了SQL:

[EL Fine]:sql:2015-01-09 12:20:51.215 - ClientSession(559179052) - Connection(1008188683) - Thread(Thread [main,5,main]) - SELECT ID, DATA_TYPE_IND,ENTRY_TYPE_IND,GRP_DESC,GRP_NAME,TRANS_ORIG_MM,TRANS_ORIG_YR FROM DUMMY_GRP WHERE(GRP_NAME =?)     bind =&gt; [TG_dabfe8]

我调试了Oracle JDBC。我能够调试JDBC到我可以看到带有bind参数的客户端Oracle Statement,如果我直接从IDE运行语句,我可以得到结果。

如果我更改&#34;等于&#34;操作员&#34;喜欢&#34; (见下文):         cq.where(cb.like(rootQuery.get(propertyName的),值+&#34;%&#34));

我得到了结果。

我相信我可能会遗漏一些简单的东西。谁能开导我?

提前致谢,

彼得C.

顺便提一下,这是Oracle JDBC Diagnositcs日志:

CONFIG:5E158F33 SQL:SELECT ID,DATA_TYPE_IND,ENTRY_TYPE_IND,GRP_DESC,GRP_NAME,TRANS_ORIG_MM,TRANS_ORIG_YR FROM DUMMY_GRP WHERE(GRP_NAME =?) java.lang.Throwable:没有错误     at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1647)     at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4401)     at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:4482)     at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:6272)     在org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1007)     在org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:642)     在org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)     在org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2002)     在org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:298)     在org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)     在org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)     在org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)     在org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)     在org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2738)     在org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2691)     at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:495)     at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1168)     在org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)     at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1127)     在org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:403)     at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1215)     at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)     在org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)     at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1786)     在org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1751)     在org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)     在org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:469)     在com.gaig.plentry.dao.DummyGroupDAOImpl.findByProperty(DummyGroupDAOImpl.java:47)     at com.gaig.plentry.dao.DummyGroupDAOImpl.findByGroupName(DummyGroupDAOImpl.java:28)     在com.gaig.plentry.dao.DummyGroupDAOImpl $$ FastClassBySpringCGLIB $$ 2d2bc23e.invoke()     在org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)     在org.springframework.aop.framework.CglibAopProxy $ CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)     在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)     at org.springframework.transaction.interceptor.TransactionInterceptor $ 1.proceedWithInvocation(TransactionInterceptor.java:99)     at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:267)     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)     在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)     在org.springframework.aop.framework.CglibAopProxy $ DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)

0 个答案:

没有答案