【发布时间】:2018-05-08 11:44:13
【问题描述】:
我正在使用带有两个数据库(Postgresql 和 MSSQL)的 Java-Hibernate。 SqlServer2012 带方言:
hibernate.dialect = org.hibernate.dialect.SQLServer2012Dialect
我写了一个标准查询,例如:
DetachedCriteria detachedCriteria=DetachedCriteria.forClass(entityClazz);
ProjectionList proj = Projections.projectionList();
proj.add(Projections.max(COMPOSEDID_VERSION_ID));
proj.add(Projections.groupProperty(COMPOSEDID_ID));
detachedCriteria.setProjection(proj);
criteria = session.createCriteria(entityClazz)
.add( Subqueries.propertiesIn(new String[] { COMPOSEDID_VERSION_ID, COMPOSEDID_ID }, detachedCriteria));
此查询在 Postgre Db 中运行良好。但是当我切换到 MSSQL 时,出现以下错误:
Caused by: java.sql.SQLException: An expression of non-boolean type specified in a context where a condition is expected, near ','.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2988)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2421)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:671)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:505)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:1029)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)[201:org.hibernate.core:5.0.0.Final]
谁能帮帮我?我应该在 Criteria API 中进行哪些更改以实现针对每个 Id 获取 maxVersion 记录的目标??
【问题讨论】:
-
您是否打开了 show_queries 以查看它想要做什么?这可能会有所帮助。见dzone.com/articles/hibernate-debugging-where-does
标签: sql-server hibernate hibernate-criteria