I have a hibernate query with a nested select:
((EntityManager)Component.getInstance("entityManager")).createQuery("SELECT e FROM someEntity e " +
"WHERE e.field1 = ?1 AND e.field2 IS NOT NULL AND " +
"e.field3 IN " +
"(SELECT t.field3 from otherEntity t " +
"WHERE t.id.field4 = ?2 " +
"AND t.field5 > 0 " +
"AND t.field6 != 'SUBMITTED')")
.setParameter(1, processor.ONE_PARAM)
.setParameter(2, processor.OTHER_PARAM)
.getResultList();
If I run this query as is, I get no errors or warnings and no results(returns null). If I change the query by replacing the 2nd parameter with the hardcoded value I get the results I expect:
((EntityManager)Component.getInstance("entityManager")).createQuery("SELECT e FROM someEntity e " +
"WHERE e.field1 = ?1 AND e.field2 IS NOT NULL AND " +
"e.field3 IN " +
"(SELECT t.field3 from otherEntity t " +
"WHERE t.id.field4 = hardcoded_other_param " +
"AND t.field5 > 0 " +
"AND t.field6 != 'SUBMITTED')")
.setParameter(1, processor.ONE_PARAM)
.getResultList();
The outer and nested query work separately and together correctly in Oracle. Do params not work in Hibernate nested selects or am I missing something?
I’m using hibernate 3.31 with JSF 1.2 and Seam 2.
Can you run the debugger and check what the query string looks looks like in each case? I’m thinking you may be missing a space or another character that you think you are including. I wouldn’t think that the nested select would be an issue.