I found out that when I run a query like "from Doc where id = 7", it works. When I run a query like "from Doc where id = ?" and pass 7 to the finder function, it breaks. Here's two log excerpts:
Code:
2005-05-07 15:01:54,968 DEBUG (SessionImpl.java:777) - find: from Doc where id = 7
2005-05-07 15:01:54,968 DEBUG (QueryParameters.java:220) - named parameters: {}
2005-05-07 15:01:54,968 DEBUG (QueryTranslatorImpl.java:207) - parse() - HQL: from od.domain.Doc where id = 7
2005-05-07 15:01:54,968 DEBUG (QueryTranslatorImpl.java:223) - --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| \-[FROM] 'from'
| \-[RANGE] 'RANGE'
| \-[DOT] '.'
| +-[DOT] '.'
| | +-[IDENT] 'od'
| | \-[IDENT] 'domain'
| \-[IDENT] 'Doc'
\-[WHERE] 'where'
\-[EQ] '='
+-[IDENT] 'id'
\-[NUM_INT] '7'
2005-05-07 15:01:54,968 DEBUG (ErrorCounter.java:72) - throwQueryException() : no errors
2005-05-07 15:01:54,968 DEBUG (HqlSqlBaseWalker.java:120) - query() << begin, level = 1
2005-05-07 15:01:54,968 DEBUG (FromElement.java:81) - FromClause{level=1} : od.domain.Doc (no alias) -> doc0_
2005-05-07 15:01:54,968 DEBUG (FromReferenceNode.java:48) - Resolved : id -> doc0_.item_id
2005-05-07 15:01:54,984 DEBUG (HqlSqlBaseWalker.java:125) - query() : finishing up , level = 1
2005-05-07 15:01:54,984 DEBUG (HqlSqlWalker.java:331) - processQuery() : ( SELECT ( FromClause{level=1} document_items doc0_ ) ( where ( = doc0_.item_id 7 ) ) )
2005-05-07 15:01:54,984 DEBUG (HqlSqlWalker.java:451) - Derived SELECT clause created.
2005-05-07 15:01:54,984 DEBUG (JoinProcessor.java:112) - Using FROM fragment [document_items doc0_ inner join items doc0_1_ on doc0_.item_id=doc0_1_.id]
2005-05-07 15:01:54,984 DEBUG (HqlSqlBaseWalker.java:128) - query() >> end, level = 1
2005-05-07 15:01:54,984 DEBUG (QueryTranslatorImpl.java:193) - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (document_items,items)
+-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
| +-[SELECT_EXPR] SelectExpressionImpl: 'doc0_.item_id as id' {FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=document_items,tableAlias=doc0_,colums={,className=od.domain.Doc}}}
| \-[SQL_TOKEN] SqlFragment: 'doc0_1_.version as version1_, doc0_1_.created as created1_, doc0_1_.price as price1_, doc0_1_.sale_price as sale5_1_, doc0_1_.on_sale as on6_1_, doc0_.name as name3_, doc0_.active as active3_, doc0_.abstract_text as abstract4_3_'
+-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[], fromElementByTableAlias=[doc0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
| \-[FROM_FRAGMENT] FromElement: 'document_items doc0_ inner join items doc0_1_ on doc0_.item_id=doc0_1_.id' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=document_items,tableAlias=doc0_,colums={,className=od.domain.Doc}}
\-[WHERE] SqlNode: 'where'
\-[EQ] SqlNode: '='
+-[SQL_TOKEN] IdentNode: 'doc0_.item_id' {originalText=id}
\-[NUM_INT] LiteralNode: '7'
2005-05-07 15:01:54,984 DEBUG (ErrorCounter.java:72) - throwQueryException() : no errors
2005-05-07 15:01:54,984 DEBUG (QueryTranslatorImpl.java:177) - HQL: from od.domain.Doc where id = 7
2005-05-07 15:01:54,984 DEBUG (QueryTranslatorImpl.java:178) - SQL: select doc0_.item_id as id, doc0_1_.version as version1_, doc0_1_.created as created1_, doc0_1_.price as price1_, doc0_1_.sale_price as sale5_1_, doc0_1_.on_sale as on6_1_, doc0_.name as name3_, doc0_.active as active3_, doc0_.abstract_text as abstract4_3_ from document_items doc0_ inner join items doc0_1_ on doc0_.item_id=doc0_1_.id where doc0_.item_id=7
2005-05-07 15:01:55,077 DEBUG (AbstractBatcher.java:277) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-05-07 15:01:55,077 DEBUG (AbstractBatcher.java:311) - select doc0_.item_id as id, doc0_1_.version as version1_, doc0_1_.created as created1_, doc0_1_.price as price1_, doc0_1_.sale_price as sale5_1_, doc0_1_.on_sale as on6_1_, doc0_.name as name3_, doc0_.active as active3_, doc0_.abstract_text as abstract4_3_ from document_items doc0_ inner join items doc0_1_ on doc0_.item_id=doc0_1_.id where doc0_.item_id=7
2005-05-07 15:01:55,077 DEBUG (AbstractBatcher.java:365) - preparing statement
2005-05-07 15:01:55,077 DEBUG (AbstractBatcher.java:293) - about to open ResultSet (open ResultSets: 0, globally: 0)
2005-05-07 15:01:55,077 DEBUG (Loader.java:384) - processing result set
2005-05-07 15:01:55,093 DEBUG (Loader.java:389) - result set row: 0
2005-05-07 15:01:55,093 DEBUG (NullableType.java:86) - returning '7' as column: id
2005-05-07 15:01:55,093 DEBUG (Loader.java:791) - result row: EntityKey[od.domain.Doc#7]
versus
Code:
2005-05-07 15:01:55,109 DEBUG (SessionImpl.java:777) - find: from Doc where id = ?
2005-05-07 15:01:55,109 DEBUG (QueryParameters.java:217) - parameters: [7]
2005-05-07 15:01:55,109 DEBUG (QueryParameters.java:220) - named parameters: {}
2005-05-07 15:01:55,109 DEBUG (QueryTranslatorImpl.java:207) - parse() - HQL: from od.domain.Doc where id = ?
2005-05-07 15:01:55,124 DEBUG (QueryTranslatorImpl.java:223) - --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| \-[FROM] 'from'
| \-[RANGE] 'RANGE'
| \-[DOT] '.'
| +-[DOT] '.'
| | +-[IDENT] 'od'
| | \-[IDENT] 'domain'
| \-[IDENT] 'Doc'
\-[WHERE] 'where'
\-[EQ] '='
+-[IDENT] 'id'
\-[PARAM] '?'
2005-05-07 15:01:55,124 DEBUG (ErrorCounter.java:72) - throwQueryException() : no errors
2005-05-07 15:01:55,124 DEBUG (HqlSqlBaseWalker.java:120) - query() << begin, level = 1
2005-05-07 15:01:55,124 DEBUG (FromElement.java:81) - FromClause{level=1} : od.domain.Doc (no alias) -> doc0_
2005-05-07 15:01:55,140 DEBUG (FromReferenceNode.java:48) - Resolved : id -> doc0_.item_id
2005-05-07 15:01:55,140 DEBUG (HqlSqlBaseWalker.java:125) - query() : finishing up , level = 1
2005-05-07 15:01:55,140 DEBUG (HqlSqlWalker.java:331) - processQuery() : ( SELECT ( FromClause{level=1} document_items doc0_ ) ( where ( = doc0_.item_id ? ) ) )
2005-05-07 15:01:55,140 DEBUG (HqlSqlWalker.java:451) - Derived SELECT clause created.
2005-05-07 15:01:55,140 DEBUG (JoinProcessor.java:112) - Using FROM fragment [document_items doc0_ inner join items doc0_1_ on doc0_.item_id=doc0_1_.id]
2005-05-07 15:01:55,140 DEBUG (HqlSqlBaseWalker.java:128) - query() >> end, level = 1
2005-05-07 15:01:55,140 DEBUG (QueryTranslatorImpl.java:193) - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (document_items,items)
+-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
| +-[SELECT_EXPR] SelectExpressionImpl: 'doc0_.item_id as id' {FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=document_items,tableAlias=doc0_,colums={,className=od.domain.Doc}}}
| \-[SQL_TOKEN] SqlFragment: 'doc0_1_.version as version1_, doc0_1_.created as created1_, doc0_1_.price as price1_, doc0_1_.sale_price as sale5_1_, doc0_1_.on_sale as on6_1_, doc0_.name as name3_, doc0_.active as active3_, doc0_.abstract_text as abstract4_3_'
+-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[], fromElementByTableAlias=[doc0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
| \-[FROM_FRAGMENT] FromElement: 'document_items doc0_ inner join items doc0_1_ on doc0_.item_id=doc0_1_.id' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=document_items,tableAlias=doc0_,colums={,className=od.domain.Doc}}
\-[WHERE] SqlNode: 'where'
\-[EQ] SqlNode: '='
+-[SQL_TOKEN] IdentNode: 'doc0_.item_id' {originalText=id}
\-[PARAM] SqlNode: '?'
2005-05-07 15:01:55,140 DEBUG (ErrorCounter.java:72) - throwQueryException() : no errors
2005-05-07 15:01:55,140 DEBUG (QueryTranslatorImpl.java:177) - HQL: from od.domain.Doc where id = ?
2005-05-07 15:01:55,140 DEBUG (QueryTranslatorImpl.java:178) - SQL: select doc0_.item_id as id, doc0_1_.version as version1_, doc0_1_.created as created1_, doc0_1_.price as price1_, doc0_1_.sale_price as sale5_1_, doc0_1_.on_sale as on6_1_, doc0_.name as name3_, doc0_.active as active3_, doc0_.abstract_text as abstract4_3_ from document_items doc0_ inner join items doc0_1_ on doc0_.item_id=doc0_1_.id where doc0_.item_id=?
2005-05-07 15:01:55,140 DEBUG (ErrorCounter.java:72) - throwQueryException() : no errors
2005-05-07 15:01:55,202 DEBUG (AbstractBatcher.java:277) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-05-07 15:01:55,202 DEBUG (AbstractBatcher.java:311) - select doc0_.item_id as id, doc0_1_.version as version1_, doc0_1_.created as created1_, doc0_1_.price as price1_, doc0_1_.sale_price as sale5_1_, doc0_1_.on_sale as on6_1_, doc0_.name as name3_, doc0_.active as active3_, doc0_.abstract_text as abstract4_3_ from document_items doc0_ inner join items doc0_1_ on doc0_.item_id=doc0_1_.id where doc0_.item_id=?
2005-05-07 15:01:55,202 DEBUG (AbstractBatcher.java:365) - preparing statement
2005-05-07 15:01:55,202 DEBUG (NullableType.java:59) - binding '7' to parameter: 1
2005-05-07 15:01:55,202 DEBUG (AbstractBatcher.java:293) - about to open ResultSet (open ResultSets: 0, globally: 0)
2005-05-07 15:01:55,202 DEBUG (Loader.java:384) - processing result set
2005-05-07 15:01:55,202 DEBUG (Loader.java:408) - done processing result set (0 rows)
2005-05-07 15:01:55,202 DEBUG (AbstractBatcher.java:300) - about to close ResultSet (open ResultSets: 1, globally: 1)
2005-05-07 15:01:55,202 DEBUG (AbstractBatcher.java:285) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2005-05-07 15:01:55,202 DEBUG (AbstractBatcher.java:403) - closing statement
2005-05-07 15:01:55,202 DEBUG (Loader.java:504) - total objects hydrated: 0
Could this be a problem with my database driver using PreparedStatements or something? I'm using MySQL version 4.1.11-nt and mysql-connector-java-3.1.8-bin.jar