Hibernate version: 3.2.6
Hi,
I'm trying to execute an SQL query
Code:
SELECT
ts.UserId ,
ts.friendid ,
t1.friendid ,
t2.friendid ,
t3.friendid ,
t4.friendid ,
td.friendid
FROM
p2p as ts ,
p2p as t1 ,
p2p as t2 ,
p2p as t3 ,
p2p as t4 ,
p2p as td
WHERE
ts.UserId = '1'
and ts.friendid = t1.UserId
and t1.friendid = t2.UserId
and t2.friendid = t3.UserId
and t3.friendid = t4.UserId
and t4.friendid = td.UserId
and td.friendid = '6'
and '1' != t1.friendid
and ts.friendid != t2.friendid
and t1.friendid != t3.friendid
and t2.friendid != t4.friendid
and t3.friendid != '6'
limit 5
when I'm executing it from SQL client i got the expected results (eg. [1,2,3,4,5,6] , [1,11,12,13,14,6]...)
but when Im doing so from Hibernate I'm getting strange results: the first and the second columns are correct, but all other columns value are the equals to the second, (eg [1,2,2,2,2,2] , [1,11,11,11,11,11],...)
Code between sessionFactory.openSession() and session.close():Code:
Query query = getSession().createSQLQuery(SQL);
List list = query.list();
I tried to do the same query, with just adding "as" to the select section :
Code:
SELECT
ts.UserId as p1,
ts.friendid as p2 ,
t1.friendid as p3 ,
t2.friendid as p4 ,
t3.friendid as p5 ,
t4.friendid as p6 ,
td.friendid as p7
FROM
....
but I get an exception for Column 'UserId' not found.
Code:
java.sql.SQLException: Column 'UserId' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1093)
at com.mysql.jdbc.ResultSetImpl.getBigDecimal(ResultSetImpl.java:1363)
at org.hibernate.type.BigIntegerType.get(BigIntegerType.java:34)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189)
at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:474)
at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:420)
at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:317)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at com.sightix.doa.hibernate.api.HibernateEntityDao.findConnection(HibernateEntityDao.java:49)
at com.sightix.doa.hibernate.EntityDaoManualSessionTest.findConnection(EntityDaoManualSessionTest.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
[WARN] [05.10.2008 17:49:59] [Thread-main] [org.hibernate.util.JDBCExceptionReporter] [Line: 77] - [SQL Error: 0, SQLState: S0022]
[ERROR] [05.10.2008 17:49:59] [Thread-main] [org.hibernate.util.JDBCExceptionReporter] [Line: 78] - [Column 'UserId' not found.]
again, executing the SQL printed in the hibernate log using SQL client work fine.
any idea?
thanks,
Rotem.