-->
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.  [ 9 posts ] 
Author Message
 Post subject: How to HQL-EagerLoad only hbm annotated collection of string
PostPosted: Tue Dec 29, 2009 2:43 pm 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
Hello,

I configure Hibernate trhough hbm and I have problems loading a collection of strings eagerly:
first my hbm config:
Code:
<list access="org.jvnet.hyperjaxb3.hibernate.accessor.ListAccessor" name="Difference" table="DifferencesToPriorStorage_Difference" fetch="join" lazy="false">
<key>
<column name="DifferencesToPriorStorage_Difference_ObjectId"/>
</key>
<list-index>
<column name="DifferencesToPriorStorage_Difference_BoSortIndex"/>
</list-index>
<element type="org.hibernate.type.StringType">
<column name="BoValue"/>
</element>
</list>


HQL:
Code:
SELECT  DISTINCT Object_JOINED1
FROM yourPackage.Object  AS  Object_JOINED1
                 LEFT JOIN FETCH          Object_JOINED1.FirstDetail      AS        FirstDetail_JOINED2
                 LEFT JOIN FETCH          Object_JOINED1.SecondDetail  AS   SecondDetail_JOINED3
                 LEFT JOIN FETCH SecondDetail_JOINED3.SubDetail       AS        SubDetail_JOINED4
                 LEFT JOIN FETCH      SubDetail_JOINED4.Difference      AS               JOINED16
WHERE   Object_JOINED1.ObjectId
        IN (  SELECT Object_JOINED0.ObjectId FROM
                 yourPackage.Object AS Object_JOINED0
            )

- Problem here is a NPE in BasicLoader.isBag(99) due the explicit join of the collection of string <element>s (alias JOINED16) , its an unannotated generated List<String> in my code
- when I remove the join of alias "JOINED16" then each Difference collection is loaded separatly after this oneShotSelect..

env:hibernate 3.2, default-lazy=false

I think there must be an option without java annotation CollectionOfElements( FetchType = Egaer).

ps: the subQuery is needed due possible "Group By Object" in it and missing object expanding... ;)

really Thx for Help & Greats !


Top
 Profile  
 
 Post subject: Re: How to HQL-EagerLoad only hbm annotated collection of string
PostPosted: Wed Dec 30, 2009 6:47 am 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
Hm.. there are two solutions of joining, My kind of depended joining according to the last joined alias is in this case unsupported.

Only due the use of collection of string the change to explicit non-depended joining is needed here, but may more performant too...

greats


Top
 Profile  
 
 Post subject: Re: How to HQL-EagerLoad only hbm annotated collection of string
PostPosted: Wed Dec 30, 2009 9:08 am 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
.. dont get it solved.

When I write LEFT JOIN then all works with following loading. When I write LEFT JOIN FETCH the previous described NPE follows :(

I think I have to write WHERE Table.ID = CHidl.ID due this collection of string.. is it so ?


Top
 Profile  
 
 Post subject: Re: How to HQL-EagerLoad only hbm annotated collection of string
PostPosted: Wed Dec 30, 2009 12:02 pm 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
I think now its time for an expert:

Like in this Post it is possible to left join fetch explicit a collection of elements.
http://stackoverflow.com/questions/1093 ... s-elements
I have tried to set @org.hibernate.annotations.CollectionOfElements , even with Fetchtype=EAGER which is already ignored..

I dont understand why this NPE follows when I change LEFT JOIN to LEFT JOIN FETCH
java.lang.NullPointerException
at org.hibernate.loader.BasicLoader.isBag(BasicLoader.java:99)
at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:78)
at org.hibernate.loader.hql.QueryLoader.<init>(QueryLoader.java:119)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1651)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:93)

When I do not join the collection of String and just join its parent with LEFT JOIN FETCH the collection is not loaded in one shot..
When I use the find method then its loaded with one shot for the requested object. I just wanna do what find() does, but in HQL, not with SQL


please Help (dedicated to an expert)


Top
 Profile  
 
 Post subject: Re: How to HQL-EagerLoad only hbm annotated collection of string
PostPosted: Wed Dec 30, 2009 12:52 pm 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
I think I got it now. Only possibility is to enumarte classed in FROM Clause an do in WHere clause: Alias.ObjectID = ChildAlias.ObjectId

corrcted: not possible du reconvertion of the SQL to multiple queries due many-to-one :(/

-> May an expert can put a short stement "not jet possible"...


Top
 Profile  
 
 Post subject: Re: How to HQL-EagerLoad only hbm annotated collection of string
PostPosted: Wed Dec 30, 2009 1:51 pm 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
I think I got it now. Only possibility is to enumarte classed in FROM Clause an do in WHere clause: Alias.ObjectID = ChildAlias.ObjectId

corrcted: not possible because I need Outer Join syntax

The question remains, why comes the NPE ?

I have tried pure @org.hibernate.annotations.CollectionOfElements annotation without Fetchtype without effects.
-> viewtopic.php?t=971700&highlight=onetomany+collectionofelements
The Query Compiler does not recognize "difference" as a bag

Next try was to verify my autodetection properties
before:
persistenceProperties.put("hibernate.archive.autodetection" , "");
persistenceProperties.put("hibernate.ejb.autodetection" , "hbm");
Now:
persistenceProperties.put("hibernate.archive.autodetection" , "");
// persistenceProperties.put("hibernate.ejb.autodetection" , "hbm"); //remarked for class,hbm default
-> NO EFFECTS, NPE remains
-> Dear Experts: Is it nice for u to watch such a MultipleCHoiceThread ? Hoply not...

some additional debug infos:

2009-12-30 20:09:09,744 [DEBUG] org.hibernate.hql.ast.tree.FromReferenceNode - Resolved : DifferencesToPriorStorage_JOINED15 -> difference14_.ObjectId
2009-12-30 20:09:09,745 [DEBUG] org.hibernate.hql.ast.tree.DotNode - getDataType() : Difference -> org.hibernate.type.ListType(yourPackage.DifferencesToPriorStorage.Difference)
2009-12-30 20:09:09,745 [DEBUG] org.hibernate.hql.ast.tree.FromElement - FromClause{level=1} : null (ABSD) -> difference15_
2009-12-30 20:09:09,745 [DEBUG] org.hibernate.hql.ast.tree.FromClause - addCollectionJoinFromElementByPath() : DifferencesToPriorStorage_JOINED15.Difference -> DifferencesToPriorStorage_Difference
2009-12-30 20:09:09,745 [DEBUG] org.hibernate.hql.ast.tree.DotNode - dereferenceCollection() : Created new FROM element for DifferencesToPriorStorage_JOINED15.Difference : DifferencesToPriorStorage_Difference difference15_
2009-12-30 20:09:09,745 [DEBUG] org.hibernate.hql.ast.tree.FromReferenceNode - Resolved : DifferencesToPriorStorage_JOINED15.Difference -> .
2009-12-30 20:09:09,745 [DEBUG] org.hibernate.hql.ast.HqlSqlWalker - createFromJoinElement() : -- join tree --
\-[JOIN_FRAGMENT] FromElement: 'DifferencesToPriorStorage_Difference difference15_' FromElement{explicit,collection join,fetch join,fetch non-lazy properties,classAlias=ABSD,role=yourPackage.DifferencesToPriorStorage.Difference,tableName={none},tableAlias=difference15_,origin=JournalEntry journalent13_,colums={,className=null}}

why is the Type null : "null (ABSD) -> difference15_"


Top
 Profile  
 
 Post subject: Re: How to HQL-EagerLoad only hbm annotated collection of string
PostPosted: Wed Dec 30, 2009 3:48 pm 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
So, I have COllectionOfElements on the List declaration and on its getter method. Hibernate ois configured to look into classed for annortations..


Last edited by Andre0815 on Thu Dec 31, 2009 10:13 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How to HQL-EagerLoad only hbm annotated collection of string
PostPosted: Thu Dec 31, 2009 10:12 am 
Beginner
Beginner

Joined: Fri Dec 04, 2009 9:37 am
Posts: 34
no matter.. i think i will get it next time and iam glad with hibernate and what is running here !
Hibernate makes really Fun and its nice to see what is reached in it.

Wiching u all a Happy new Year !

Andre


Top
 Profile  
 
 Post subject: Re: How to HQL-EagerLoad only hbm annotated collection of string
PostPosted: Mon Jul 19, 2010 10:40 am 
Newbie

Joined: Tue Feb 03, 2009 9:26 am
Posts: 3
I got this error also, and it appears to be a bug in Hibernate up until at least 3.3.2

In org.hibernate.loader.BasicLoader at line 72 there is the following code:
Code:
      CollectionPersister[] collectionPersisters = getCollectionPersisters();
      List bagRoles = null;
      if ( collectionPersisters != null ) {
         String[] collectionSuffixes = getCollectionSuffixes();
         collectionDescriptors = new CollectionAliases[collectionPersisters.length];
         for ( int i = 0; i < collectionPersisters.length; i++ ) {
            if ( isBag( collectionPersisters[i] ) ) {
               ....................................

For some reason, one of the values in the collectionPersisters[] is null, which generates a NullPointerException inside isBag:
Code:
   private boolean isBag(CollectionPersister collectionPersister) {
      return collectionPersister.getCollectionType().getClass().isAssignableFrom( BagType.class );
   }

As seen on line 72, this array of CollectionPersisters is returned by getCollectionPersisters(), which has multiple implementations, and the problem is definitely in one of these implementations, but I didn't have time yet to check where...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.