Hi
I have a User object, that have some details, a list of it's friends, and invert list of friends (friends of him).
When I config the lists to be lazy, it's work fine, but when I set it to be extra-lazy, I get "Column 'FriendId' not found" exception.
Hibernate version: 3.2.6
Mapping documents:
Code:
<class name="Entity">
<id name="id" column="ID">
<generator class="native" />
</id>
<properties name="snsID_userID_Unique" unique="true">
<property name="snsId" />
<property name="userId" />
</properties>
<property name="name" />
<map name="friends" table="p2p" lazy="extra" >
<key column="UserId" />
<map-key formula="FriendId" type="long" column="UserId"/>
<many-to-many column="FriendId" class="Entity" />
</map>
<map name="friendOf" table="p2p" lazy="extra" inverse="true">
<key column="FriendId" />
<map-key formula="UserId" type="long" column="FriendId"/>
<many-to-many column="UserId" class="Entity" />
</map>
</class>
Code between sessionFactory.openSession() and session.close():Code:
Entity loadByID = entityDao.loadByID(new Long(14));
Map<Long, Entity> friends = loadByID.getFriends();
Entity e = friends.get(new Long(13));
At the third line I get the exception
Code:
[DEBUG] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.jdbc.AbstractBatcher] [Line: 366] - [about to open PreparedStatement (open PreparedStatements: 0, globally: 0)]
[DEBUG] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.SQL] [Line: 401] - [
select
FriendId as formula0_
from
test.p2p
where
UserId =?
and FriendId =?]
Hibernate:
select
FriendId as formula0_
from
test.p2p
where
UserId =?
and FriendId =?
[DEBUG] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.jdbc.AbstractBatcher] [Line: 484] - [preparing statement]
[DEBUG] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.type.LongType] [Line: 133] - [binding '14' to parameter: 1]
[DEBUG] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.type.LongType] [Line: 133] - [binding '13' to parameter: 2]
[INFO] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.type.LongType] [Line: 182] - [could not read column value from result set: FriendId; Column 'FriendId' not found.]
[DEBUG] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.jdbc.AbstractBatcher] [Line: 374] - [about to close PreparedStatement (open PreparedStatements: 1, globally: 1)]
[DEBUG] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.jdbc.AbstractBatcher] [Line: 533] - [closing statement]
[DEBUG] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.util.JDBCExceptionReporter] [Line: 69] - [could not read row: [com.sightix.data.Entity.friends#14] [select count(FriendId) from test.p2p where UserId =?]]
java.sql.SQLException: Column 'FriendId' 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.getLong(ResultSetImpl.java:2942)
at org.hibernate.type.LongType.get(LongType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:103)
at org.hibernate.type.EntityType.nullSafeGet(EntityType.java:204)
at org.hibernate.persister.collection.AbstractCollectionPersister.getElementByIndex(AbstractCollectionPersister.java:1753)
at org.hibernate.collection.AbstractPersistentCollection.readElementByIndex(AbstractPersistentCollection.java:158)
at org.hibernate.collection.PersistentMap.get(PersistentMap.java:146)
at com.sightix.doa.hibernate.EntityDaoManualSessionTest.get(EntityDaoManualSessionTest.java:72)
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] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.util.JDBCExceptionReporter] [Line: 77] - [SQL Error: 0, SQLState: S0022]
[ERROR] [06.10.2008 17:29:49] [Thread-main] [org.hibernate.util.JDBCExceptionReporter] [Line: 78] - [Column 'FriendId' not found.]
If I'm running the SQL queries from the Hibernate log on the DB they work fine.
How can I solve this?
thanks,
Rotem.