如何将 Restrictions.in 与列表字段一起使用?
这是我的模型:
@Entity
@Table(name = "W_GROUP", schema = "U_FRONTEND")
public class UserGroup {
@Id
@Column(name = "GROUP_ID")
private Long id;
@Column(name = "NAME", length = 100, nullable = false, unique = true)
private String name;
@ElementCollection(targetClass = Feature.class)
@JoinTable(name = "W_FEATURE", joinColumns = @JoinColumn(name = "GROUP_ID", nullable = false), schema = "U_FRONTEND")
@Column(name = "NAME", nullable = false, length = 50)
@Enumerated(EnumType.STRING)
private List<Feature> features;
@JoinTable(name = "W_USER_GROUP", joinColumns = @JoinColumn(name = "GROUP_ID"), inverseJoinColumns = @JoinColumn(name = "USER_ID"), schema = "U_FRONTEND")
@ManyToMany
private List<User> users;
@Column(name = "UPD_USER", nullable = false, length = 50)
private String updUser;
@Column(name = "UPD_DATE", nullable = false, columnDefinition = "date")
private Calendar updDate;
// Getters and setters
}
我正在尝试仅获取具有某些功能的组:
Criteria criteria = session.createCriteria(UserGroup.class);
criteria.addOrder(new Sort(Order.ASC, "name").getOrder());
criteria.add(Restrictions.not(Restrictions.in("features",
FeatureUtils.getInvalids())));
但这会返回一个错误:
原因:org.hibernate.exception.GenericJDBCException:在 org.hibernate.engine.jdbc.spi 的 org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) 处缺少 IN 或 OUT 参数索引:: 1 .SqlExceptionHelper.convert(SqlExceptionHelper.java:125) 在 org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) 在 org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler .java:129) 在 org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) 在 $Proxy35.executeQuery(Unknown Source) 在 org.hibernate.loader.Loader.getResultSet(Loader. java:1926) 在 org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1727) 在 org.hibernate.loader.Loader.doQuery(Loader.java:852) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293) at org.hibernate.loader.Loader.doList(Loader.java:2411) at org .hibernate.loader.Loader.doList(Loader.java:2397) 在 org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2227) 在 org.hibernate.loader.Loader.list(Loader.java:2222) 在org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:122) 在 org.hibernate.internal.SessionImpl.list(SessionImpl.java:1621) 在 org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java: 374) 在 hamburgsud.frontend.dao.UserGroupDAO.list(UserGroupDAO.java:39) 在 hamburgsud.frontend.controller.UserController.form(UserController.java:38) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun 。反映。NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在 java.lang.reflect.Method.invoke(Method.java:597) 在 br.com.caelum.vraptor .interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:61) ... 43 更多原因:java.sql.SQLException:索引处缺少 IN 或 OUT 参数::oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError. java:112) 在 oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1681) 在 oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement) 的 oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) .java:3280) 在 oracle.jdbc.driver.OraclePreparedStatement。com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke( NativeMethodAccessorImpl.java:39) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在 java.lang.reflect.Method.invoke(Method.java:597) 在 org.hibernate.engine.jdbc.internal.proxy .AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) ... 63 更多NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.hibernate.engine.jdbc .internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) ... 63 更多NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.hibernate.engine.jdbc .internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) ... 63 更多