The following query is parsed correctly but generates invalid sql statement.
Query query = s.createQuery("select n from Node n, Language l where index(n.metadata) = l and l.code=:langcode");
query.setString("langcode","en");
List list = query.list();
The correct sql statement would be:
SELECT node0_.treeid AS treeid, node0_.version AS version0_, node0_.lastmodifieddate AS lastmodi3_0_, node0_.lastmodifiedby AS lastmodi4_0_,
node0_.nodetypeid AS nodetypeid0_, node0_.createuser AS createuser0_, node0_.owneruser AS owneruser0_, node0_.statusid AS statusid0_,
node0_.creationDate AS creation9_0_, node0_.system AS system0_, node0_.orderid AS orderid0_, node0_.parentid AS parentid0_,
node0_.deletedid AS deletedid0_, node0_.deletedroot AS deleted14_0_, node0_.inheritsPermissions AS inherit15_0_,
node0_.shortcutid AS shortcutid0_,
(CASE WHEN node0_.nodetypeid = 2 THEN 'S' WHEN node0_.nodetypeid = 12 THEN 'G' WHEN node0_.nodetypeid = 1 THEN 'U' WHEN node0_.nodetypeid
= 5 THEN 'R' WHEN 1 = 1 THEN 'C' ELSE 'N' END) AS clazz_
FROM ttree node0_, tmetadata metadata2_, tlang language1_
WHERE (metadata2_.treeid = node0_.treeid AND metadata2_.langid = language1_.id AND language1_.code = ?)
The node entity has a metadata Map mapped as:
<map name="metadata" cascade="all-delete-orphan" access="field">
<key column="treeid"/>
<map-key-many-to-many
column="langid" class="Language"/>
<one-to-many class="MetaData"/>
</map>
Any ideas?
Hibernate version: 3 rc1
Full stack trace of any exception that occurs:
15 Μαρ 2005 3:16:32 μμ org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 107, SQLState: S1000
15 Μαρ 2005 3:16:32 μμ org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: The column prefix 'metadata2_' does not match with a table name or alias name used in the query.
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:365)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:268)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:782)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at exodus.ecentric.test.EntityTest.testGetNodesByLanguage(EntityTest.java:446)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at exodus.model.test.TestCase.runTest(TestCase.java:60)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
Caused by: java.sql.SQLException: The column prefix 'metadata2_' does not match with a table name or alias name used in the query.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:367)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2606)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2048)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:574)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:321)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:667)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
at org.hibernate.loader.Loader.doQuery(Loader.java:363)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
... 22 more
Name and version of the database you are using:
ms sql server
The generated SQL (show_sql=true):
select node0_.treeid as treeid, node0_.version as version0_, node0_.lastmodifieddate as lastmodi3_0_, node0_.lastmodifiedby as lastmodi4_0_, node0_.nodetypeid as nodetypeid0_, node0_.createuser as createuser0_, node0_.owneruser as owneruser0_, node0_.statusid as statusid0_, node0_.creationDate as creation9_0_, node0_.system as system0_, node0_.orderid as orderid0_, node0_.parentid as parentid0_, node0_.deletedid as deletedid0_, node0_.deletedroot as deleted14_0_, node0_.inheritsPermissions as inherit15_0_, node0_.shortcutid as shortcutid0_,
( case
when node0_.nodetypeid = 2 then 'S'
when node0_.nodetypeid = 12 then 'G'
when node0_.nodetypeid = 1 then 'U'
when node0_.nodetypeid = 5 then 'R'
when 1 /*dbo.isContainer(node0_.nodetypeid)*/ = 1 then 'C'
else 'N'
end )
as clazz_ from ttree node0_, tlang language1_ where (metadata2_.langid=language1_.id and language1_.code=?)
|