-->
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.  [ 4 posts ] 
Author Message
 Post subject: loadByUniqueKey error and many-to-many w/join table.
PostPosted: Fri Jan 05, 2007 1:50 pm 
Newbie

Joined: Fri Jul 15, 2005 10:02 am
Posts: 12
using hibernate 3.2.1

I am mapping a many-to-many collection across a join table. Everything seems to load the proper data but I can not figure out why this error is getting generated. Any ideas would be greatly appreciated.

mappings

Code:
<class name="model.aws.AwsChannel" table="TBLCHANNEL">
        <id name="id" column="CHANNELID">
         <generator class="assigned" />
        </id>
        <property name="siteId" column="SITEID" />
        <property name="parentChannelId" column="PARENTCHANNELID" />
        <property name="legacyId" column="LEGACY_ID" />
        <property name="name" column="NAME" />
        <property name="description" column="DESCRIPTION" />
        <property name="active" column="ISACTIVE" />
        <property name="userCreated" column="USER_CREATED" />
        <property name="userModified" column="USER_MODIFIED" />
        <property name="dateCreated" column="DATE_CREATED" />
        <property name="dateModified" column="DATE_MODIFIED" />

        <set name="permissionSet" table="TBLCHANNELCONTENTMAPPING" where="guid in (select a.guid from bnp_permissions a)">
            <key column="CHANNELID" />
             <many-to-many column="GUID" property-ref="guid" not-found="ignore" class="model.security.Permission" />
        </set>

    </class>

<class name="model.security.Permission" table="BNP_PERMISSIONS">
        <id name="id" column="PERMISSION_ID">
         <generator class="assigned"/>
        </id>
        <property name="guid" column="GUID" unique="true" not-null="true" />
        <property name="title" column="TITLE" />
        <property name="plevel" column="PLEVEL" />
       
    </class>


log output
Code:
2007-01-05 12:58:35,277 DEBUG [org.hibernate.loader.Loader] loading collection: [model.aws.AwsChannel.permissionSet#23601]
2007-01-05 12:58:35,277 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2007-01-05 12:58:35,277 DEBUG [org.hibernate.SQL] select permission0_.CHANNELID as CHANNELID1_, permission0_.GUID as GUID1_, permission1_.PERMISSION_ID as PERMISSION1_27_0_, permission1_.GUID as GUID27_0_, permission1_.TITLE as TITLE27_0_, permission1_.PLEVEL as PLEVEL27_0_ from TBLCHANNELCONTENTMAPPING permission0_ left outer join BNP_PERMISSIONS permission1_ on permission0_.GUID=permission1_.GUID where  ( permission0_.guid in (select a.guid from bnp_permissions a))  and permission0_.CHANNELID=?
2007-01-05 12:58:35,277 DEBUG [org.hibernate.jdbc.AbstractBatcher] preparing statement
2007-01-05 12:58:35,277 DEBUG [org.hibernate.type.LongType] binding '23601' to parameter: 1
2007-01-05 12:58:35,277 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open ResultSet (open ResultSets: 0, globally: 0)
2007-01-05 12:58:35,277 DEBUG [org.hibernate.loader.Loader] result set contains (possibly empty) collection: [model.aws.AwsChannel.permissionSet#23601]
2007-01-05 12:58:35,277 DEBUG [org.hibernate.engine.CollectionLoadContext] uninitialized collection: initializing
2007-01-05 12:58:35,277 DEBUG [org.hibernate.loader.Loader] processing result set
2007-01-05 12:58:35,277 DEBUG [org.hibernate.loader.Loader] result set row: 0
2007-01-05 12:58:35,277 DEBUG [org.hibernate.type.LongType] returning '2' as column: PERMISSION1_27_0_
2007-01-05 12:58:35,277 DEBUG [org.hibernate.loader.Loader] result row: EntityKey[model.security.Permission#2]
2007-01-05 12:58:35,277 DEBUG [org.hibernate.type.LongType] returning '23601' as column: CHANNELID1_
2007-01-05 12:58:35,277 DEBUG [org.hibernate.loader.Loader] found row of collection: [model.aws.AwsChannel.permissionSet#23601]
2007-01-05 12:58:35,277 DEBUG [org.hibernate.engine.CollectionLoadContext] reading row
2007-01-05 12:58:35,277 DEBUG [org.hibernate.type.StringType] returning '6074c07f0d36c010VgnVCM100000f932a8c0____' as column: GUID1_
2007-01-05 12:58:35,277 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close ResultSet (open ResultSets: 1, globally: 1)
2007-01-05 12:58:35,277 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2007-01-05 12:58:35,277 DEBUG [org.hibernate.jdbc.AbstractBatcher] closing statement
2007-01-05 12:58:35,277 WARN  [ui.widget.plugin.AbstractWidget] processOutput(): could not get channel information for widget. Clearing contents to prevent faulty display.
java.lang.NullPointerException
   at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:1596)
   at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:608)
   at org.hibernate.type.EntityType.resolve(EntityType.java:382)
   at org.hibernate.type.EntityType.nullSafeGet(EntityType.java:204)
   at org.hibernate.persister.collection.AbstractCollectionPersister.readElement(AbstractCollectionPersister.java:703)
   at org.hibernate.collection.PersistentSet.readFrom(PersistentSet.java:318)
   at org.hibernate.loader.Loader.readCollectionElement(Loader.java:994)
   at org.hibernate.loader.Loader.readCollectionElements(Loader.java:634)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:579)
   at org.hibernate.loader.Loader.doQuery(Loader.java:689)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
   at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
   at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:163)


Top
 Profile  
 
 Post subject: Re: loadByUniqueKey error and many-to-many w/join table.
PostPosted: Fri Jan 05, 2007 5:35 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
merkkila wrote:
Code:
<set name="permissionSet" table="TBLCHANNELCONTENTMAPPING" where="guid in (select a.guid from bnp_permissions a)">
            <key column="CHANNELID" />
             <many-to-many column="GUID" property-ref="guid" not-found="ignore" class="model.security.Permission" />
</set>

I can't see why you've such error.

Maybe try temporarily removing the where and table attributes on your set, and maybe also property-ref and not-found on the many-to-many. This way, you can see if the problem goes away and reduce the fields of possibilites :-).

my 2 cents...

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: WORKAROUND FOUND
PostPosted: Mon Oct 06, 2008 8:56 pm 
Newbie

Joined: Tue May 30, 2006 1:33 pm
Posts: 5
Problem remains in 3.3.1.GA

Debbuging Hibernate's code I found that the AbstractEntityPersister tries to use an "static key loader" from the map "uniqueKeyLoaders" which is always empty, hence -> NPE (line 1681)

There is some logic in the "getAppropriateUniqueKeyLoader" and we can make it not to create it's own "uniqueKeyLoader" and avoid NPE.

The result ends being a clean workaround and worked for the webapp we are building.

For some reason, if there is a filter enabled in the session, it will not use the "static key loader" and will create one. For that reason, I created a dummy Filter and enabled it. The filter does nothing, it's just there to make an "if condition" false.

the hbm for the parent must have the filter for the many-to-many relation like this:

Code:
      <map name="positionDetailDatesMap" table="so_owner.op_voyage_positions" mutable="false" inverse="true" >
         <key>
            <column name="company_id"></column>
            <column name="ship_id"></column>
            <column name="voyage_no"></column>
         </key>
         <map-key type="long" formula="key_position"></map-key>
         <many-to-many class="com.osg.chops.shipboard.domain.PositionDetailsDates" property-ref="keyPosition" order-by="arr_datetime asc" not-found="ignore">
            <formula>key_position</formula>
         </many-to-many>
         <filter name="myFilter" condition="1=1"></filter>
      </map>


Also, in the same file, somewhere at the end declare the filter

Code:
   <filter-def name="myFilter">

   </filter-def>


The final blow to it is to enable the filter for the current session.

Code:
currentSession.enableFilter("myFilter");


In my case I have a request filter and we use one session per request, so I make sure to run thi code on every request.

I'd love to know what the problem may be. This is just a workaround and Im not sure in deep how this affect hibernate behavior, performance, etc.

Can someone please bring more light on this?
bye bye
Dj


Top
 Profile  
 
 Post subject: Re: loadByUniqueKey error and many-to-many w/join table.
PostPosted: Tue Jul 26, 2011 5:00 am 
Newbie

Joined: Tue Apr 27, 2010 5:18 pm
Posts: 19
Hi.

I had the same problem and the solution / work around it still working fine in Hibernate 3.6

Thanks for posting the solution.
It seems like Hibernate is a little weaker when not using the primary key, rather a natural id

Martin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.