[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2258?page=c...
]
Darryl Miles commented on HHH-2258:
-----------------------------------
Attached is a logging output of testcase here are the notable entries.
13:34:02,609 DEBUG DotNode:591 - getDataType() : productDetail ->
org.hibernate.type.ManyToOneType(org.hibernate.test.joinedmapfilter.ProductDetail)
13:34:02,610 DEBUG DotNode:390 - dereferenceEntityJoin() : generating join for
productDetail in org.hibernate.test.joinedmapfilter.Toplevel {no alias} parent = [ ( . (
. toplevel0_.toplevel_id productDetail ) attributes ) ]
13:34:02,616 DEBUG FromElement:131 - FromClause{level=1} :
org.hibernate.test.joinedmapfilter.ProductDetail (no alias) -> productdet1_
13:34:02,617 DEBUG FromClause:257 - addJoinByPathMap() : r.productDetail ->
product_detail productdet1_
13:34:02,618 DEBUG FromReferenceNode:74 - Resolved : r.productDetail ->
toplevel0_.product_detail_id
Notice here the 2nd FROM_FRAGMENT of ImpliedFromElement with '' as the getText().
This should be 'product_detail productdet1_' you can see it knows the tableName
and tableAlias but the getText() is blank.
13:34:02,680 DEBUG AST:258 - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces
(product_detail_attrs,toplevel,product_detail)
+-[SELECT_CLAUSE] SelectClause: '{select clause}'
| +-[ALIAS_REF] IdentNode: 'toplevel0_.toplevel_id as toplevel1_0_' {alias=r,
className=org.hibernate.test.joinedmapfilter.Toplevel, tableAlias=toplevel0_}
| \-[SQL_TOKEN] SqlFragment: 'toplevel0_.long_value_one as long2_0_,
toplevel0_.product_detail_id as product3_0_, toplevel0_.description as descript4_0_'
+-[FROM] FromClause: 'FROM' FromClause{level=1, fromElementCounter=2,
fromElements=3, fromElementByClassAlias=[r], fromElementByTableAlias=[toplevel0_,
productdet1_, attributes2_], fromElementsByPath=[r.productDetail],
collectionJoinFromElementsByPath=[r.productDetail.attributes], impliedElements=[]}
| +-[FROM_FRAGMENT] FromElement: 'toplevel toplevel0_'
FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy
properties,classAlias=r,role=null,tableName=toplevel,tableAlias=toplevel0_,origin=null,colums={,className=org.hibernate.test.joinedmapfilter.Toplevel}}
| +-[FROM_FRAGMENT] ImpliedFromElement: ''
ImpliedFromElement{implied,collection join,not a fetch join,fetch non-lazy
properties,classAlias=null,role=null,tableName=product_detail,tableAlias=productdet1_,origin=toplevel
toplevel0_,colums={toplevel0_.product_detail_id
,className=org.hibernate.test.joinedmapfilter.ProductDetail}}
| \-[FROM_FRAGMENT] ImpliedFromElement: 'product_detail_attrs attributes2_'
ImpliedFromElement{implied,collection join,not a fetch join,fetch non-lazy
properties,classAlias=null,role=org.hibernate.test.joinedmapfilter.ProductDetail.attributes,tableName={none},tableAlias=attributes2_,origin=toplevel
toplevel0_,colums={,className=null}}
\-[WHERE] SqlNode: 'WHERE'
+-[THETA_JOINS] SqlNode: '{theta joins}'
| +-[SQL_TOKEN] SqlFragment:
'toplevel0_.product_detail_id=productdet1_.product_detail_id'
| \-[SQL_TOKEN] SqlFragment:
'productdet1_.product_detail_id=attributes2_.product_detail_id and attributes2_.name =
?'
\-[AND] SqlNode: 'AND'
+-[EQ] BinaryLogicOperatorNode: '='
| +-[DOT] DotNode: 'toplevel0_.toplevel_id'
{propertyName=toplevelId,dereferenceType=4,propertyPath=toplevelId,path=r.toplevelId,tableAlias=toplevel0_,className=org.hibernate.test.joinedmapfilter.Toplevel,classAlias=r}
| | +-[ALIAS_REF] IdentNode: 'toplevel0_.toplevel_id' {alias=r,
className=org.hibernate.test.joinedmapfilter.Toplevel, tableAlias=toplevel0_}
| | \-[IDENT] IdentNode: 'toplevelId' {originalText=toplevelId}
| \-[PARAM] ParameterNode: '?' {ordinal=0,
expectedType=org.hibernate.type.LongType@6e3e5e}
\-[EQ] BinaryLogicOperatorNode: '='
+-[INDEX_OP] IndexNode: 'attributes2_.value'
{ImpliedFromElement{implied,collection join,not a fetch join,fetch non-lazy
properties,classAlias=null,role=org.hibernate.test.joinedmapfilter.ProductDetail.attributes,tableName={none},tableAlias=attributes2_,origin=toplevel
toplevel0_,colums={,className=null}}}
| +-[DOT] DotNode: '.'
{propertyName=attributes,dereferenceType=3,propertyPath=attributes,path=r.productDetail.attributes,tableAlias=attributes2_,className=null,classAlias=null}
| | +-[DOT] DotNode: 'toplevel0_.product_detail_id'
{propertyName=productDetail,dereferenceType=1,propertyPath=productDetail,path=r.productDetail,tableAlias=productdet1_,className=org.hibernate.test.joinedmapfilter.ProductDetail,classAlias=null}
| | | +-[ALIAS_REF] IdentNode: 'toplevel0_.toplevel_id' {alias=r,
className=org.hibernate.test.joinedmapfilter.Toplevel, tableAlias=toplevel0_}
| | | \-[IDENT] IdentNode: 'productDetail'
{originalText=productDetail}
| | \-[IDENT] IdentNode: 'attributes' {originalText=attributes}
| \-[PARAM] ParameterNode: '?' {ordinal=1, expectedType=null}
\-[PARAM] ParameterNode: '?' {ordinal=2, expectedType=null}
There is also ./core/src/main/java/org/hibernate/hql/ast/SqlGenerator.java around line
249. I guess my missing table in the FROM clause is one of these "ghosts".
///////////////////////////////////////////////////////////////////////
// HACK ALERT !!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Attempt to work around "ghost" ImpliedFromElements that
occasionally
// show up between the actual things being joined. This consistently
// occurs from index nodes (at least against many-to-many). Not sure
// if there are other conditions
//
// Essentially, look-ahead to the next FromElement that actually
// writes something to the SQL
while ( right != null && !hasText( right ) ) {
right = ( FromElement ) right.getNextSibling();
}
if ( right == null ) {
return;
}
///////////////////////////////////////////////////////////////////////
Bad SQL Grammer: Implicit join when using r.fooClass.attributes[?]=?
--------------------------------------------------------------------
Key: HHH-2258
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2258
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.1.3
Environment: MySQL server this has been tested with.
Reporter: Darryl Miles
Priority: Critical
Attachments: HHH-2258.txt, test_joinedmapfilter.zip
Please find this test case atteched to demonstrate the bug, maybe you can add to the
hibernate distribution for future testing and piece of mind for me.
The error:
Testsuite: org.hibernate.test.joinedmapfilter.JoinedMapFilterTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.498 sec
Testcase: testJoinedMapFilter took 0.495 sec
Caused an ERROR
could not execute query
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
at org.hibernate.loader.Loader.list(Loader.java:2023)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at
org.hibernate.test.joinedmapfilter.JoinedMapFilterTest.testJoinedMapFilter(JoinedMapFilterTest.java:116)
at org.hibernate.test.TestCase.runTest(TestCase.java:250)
at org.hibernate.test.TestCase.runBare(TestCase.java:316)
Caused by: java.sql.SQLException: Unknown table 'productdet1_' in where clause
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2994)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1668)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2144)
... 25 more
SELECT r FROM com.company.Toplevel AS r WHERE r.toplevel=? AND
rec.productDetail.attributes[?]=?
Also my recent post:
http://forum.hibernate.org/viewtopic.php?t=966374&start=0&postday...
This testcase has been tested with 3.1.3 and 3.2.0-ga.
2nd problem:
There is also another situation in the testcase which I found through serendipity which
causes a NPE inside hibernate because I misspelled "r" as "rec".
Check out the commented out section and swap over the createQuery() lines to demonstrate
that NPE.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira