-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: problem with extra-lazy map
PostPosted: Mon Oct 06, 2008 11:40 am 
Newbie

Joined: Sun Oct 05, 2008 11:29 am
Posts: 9
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2008 11:44 am 
Newbie

Joined: Sun Oct 05, 2008 11:29 am
Posts: 9
does some one know what is the problem ?

Rotem.


Top
 Profile  
 
 Post subject: ??
PostPosted: Wed Oct 15, 2008 4:17 am 
Newbie

Joined: Sun Oct 05, 2008 11:29 am
Posts: 9
ping...


Top
 Profile  
 
 Post subject: another update
PostPosted: Wed Oct 22, 2008 10:53 am 
Newbie

Joined: Sun Oct 05, 2008 11:29 am
Posts: 9
When I'm trying to fetch the whole list, or get the size, it's work ok.
but when I'm trying to load specific key it's throws the exception. (even though it generate the right SQL query, I run it manually and it's work).

any ideas?
thanks,
Rotem.


Top
 Profile  
 
 Post subject: Re: problem with extra-lazy map
PostPosted: Fri May 07, 2010 12:43 pm 
Newbie

Joined: Fri May 07, 2010 12:34 pm
Posts: 1
Hi Roteri, understand this thread is pretty old, but I've experienced all sorts of difficulties with extra-lazy maps recently and I thought I'd take a moment to help in this case. I found this question when trying to solve my own problem, so perhaps an explanation might help other users.

There is a bug opened that states that a formula based index on a map coupled with lazy="extra" is broken, it hasn't been fixed yet. They suggest to parenthesis the column in your formula, it will fix the problem in your case, it worked in mine! It's a dirty hack, but..

ie. change

Code:
<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>

to:

Code:
<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>


The open bug in question:
http://opensource.atlassian.com/project ... se/HHH-788

Other (slightly) related extra-lazy and plain lazy map bugs that have tripped me up today also:

You have to delete twice from un-initialized lazy maps (or initialize then delete)
http://opensource.atlassian.com/project ... e/HHH-3223

And, extra-lazy maps with a WHERE clause will return an incorrect .size() value. The WHERE is ignored.
http://opensource.atlassian.com/project ... e/HHH-1491

Ta,
Derek


Top
 Profile  
 
 Post subject: Re: problem with extra-lazy map
PostPosted: Sat May 08, 2010 2:07 am 
Newbie

Joined: Sun Oct 05, 2008 11:29 am
Posts: 9
hi Derek,
Thanks for you reply
My problem indeed old, and not relevant any more, but I guess it can help others.
It's not so dirty/ugly hack, because it in the configuration file and not code one. :)

I'll remember this for the next time... :)

Thanks,
Rotem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.