Statement « Criteria « JPA Q&A





1. How to make NOT IN statement via Restrictions    stackoverflow.com

I used this trick:

List statuses = new ArrayList();
Criteria criteria = session.createCriteria(MessageQueue.class);
criteria.add(Restrictions.not(Restrictions.in("message_status", statuses)));
and this code creates:
...from MESSAGE_QUEUE mq where not (mq.message_status in (?, ?, ?, ?))...
but I need:
...from MESSAGE_QUEUE mq where mq.message_status ...

2. Criteria generate wrong SQL statement    forum.hibernate.org

Full stack trace of any exception that occurs: Caused by: java.sql.SQLException: ORA-00904: "Y4_": invalid identifier at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:282) at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:639) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:185) at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:503) at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:965) at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:535) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1051) at oracle.jdbc.driver.OracleStatement.doScrollExecuteCommon(OracleStatement.java:3807) at oracle.jdbc.driver.OraclePreparedStatement.doScrollPstmtExecuteUpdate(OraclePreparedStatement.java:9209) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2982) at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3026) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186) at org.hibernate.loader.Loader.getResultSet(Loader.java:1787) at org.hibernate.loader.Loader.scroll(Loader.java:2286) ... 30 more

3. Criteria: Substring With In Statement    forum.hibernate.org

I'm getting exception when trying to use substring with criteria. (could use "or" Restrictions instead of "in" to accomplish the same thing, but really would like to get this to work) The SQL generated will run in both DBVisualizer and seems to be running thru Hibernate, but when the resultset is returned, I get an exception: Code: Session session = this.getSession(); ...