-->
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.  [ 1 post ] 
Author Message
 Post subject: named query NullPointer in Loader.handleEmptyCollection
PostPosted: Thu Sep 21, 2006 10:12 am 
Newbie

Joined: Thu Sep 21, 2006 9:50 am
Posts: 5
I'm trying named query for loading a collection, but i have a NullPointerException in org.hibernate.loader.Loader.handleEmptyCollections as you can see in Exception trace.
I have tested query ad it is correct.
What's wrong?

Hibernate version:3.1.3

Mapping documents:
Code:
<hibernate-mapping>
   <class name="associable_0N0N.Cliente" table="cliente">
      <id name="id" />
      <property name="name" />
      
      <bag name="destinatarioAssociati" table="cliente_destinatario">
         <key column="cliente_id" />
         <many-to-many column="destinatario_id" class="associable_0N0N.Destinatario" />
      </bag>

      <bag name="destinatarioAssociabili" >
         <key />
         <many-to-many class="associable_0N0N.Destinatario" />
         <loader query-ref="associable_0N0N.Cliente.destinatarioAssociabili" />
      </bag>
      
      <sql-query name="destinatarioAssociabili">
         select *
         from
            destinatario as d left outer join
            cliente_destinatario as cd on d.id=cd.destinatario_id
         where
            cd.cliente_id = ?
      </sql-query>   
      
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
        session.beginTransaction();

        Cliente c1 = (Cliente) session.load(Cliente.class,new Long(1));
       
        System.out.println("caricato Cliente "+c1.getId());
        System.out.println(c1.getName());

        System.out.println("destinatari associati:");
        for(Destinatario d: c1.getDestinatarioAssociati())
            System.out.println(d.getName());

        System.out.println("destinatari associabili:");
        for(Destinatario d: c1.getDestinatarioAssociabili())
            System.out.println(d.getName());
       
        session.getTransaction().commit();


Full stack trace of any exception that occurs:
Code:
Exception in thread "main" java.lang.NullPointerException
   at org.hibernate.loader.Loader.handleEmptyCollections(Loader.java:1035)
   at org.hibernate.loader.Loader.doQuery(Loader.java:678)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2145)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111)
   at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1655)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)
   at org.hibernate.persister.collection.NamedQueryCollectionInitializer.initialize(NamedQueryCollectionInitializer.java:54)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
   at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1676)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentBag.iterator(PersistentBag.java:246)
   at associable_0N0N.Associable_0N0N_Test.main(Associable_0N0N_Test.java:30)



Name and version of the database you are using:SQLServer 8.00.760(SP3)

Debug level Hibernate log excerpt:
Code:
destinatari associabili:
15:50:32,379 DEBUG DefaultInitializeCollectionEventListener:41 - initializing collection [associable_0N0N.Cliente.destinatarioAssociabili#1]
15:50:32,379 DEBUG DefaultInitializeCollectionEventListener:47 - checking second-level cache
15:50:32,379 DEBUG DefaultInitializeCollectionEventListener:59 - collection not cached
15:50:32,379 DEBUG NamedQueryCollectionInitializer:34 - initializing collection: associable_0N0N.Cliente.destinatarioAssociabili using named query: associable_0N0N.Cliente.destinatarioAssociabili
15:50:32,410 DEBUG SessionImpl:1253 - setting flush mode to: NEVER
15:50:32,410 DEBUG QueryPlanCache:117 - located native-sql query plan in cache (select *
         from
            destinatario as d left outer join
            cliente_destinatario as cd on d.id=cd.destinatario_id
         where
            cd.cliente_id = ?)
15:50:32,410 DEBUG SessionImpl:1645 - SQL query: select *
         from
            destinatario as d left outer join
            cliente_destinatario as cd on d.id=cd.destinatario_id
         where
            cd.cliente_id = ?
15:50:32,410 DEBUG AbstractBatcher:311 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
15:50:32,410 DEBUG SQL:346 - select *
         from
            destinatario as d left outer join
            cliente_destinatario as cd on d.id=cd.destinatario_id
         where
            cd.cliente_id = ?
Hibernate: select *
         from
            destinatario as d left outer join
            cliente_destinatario as cd on d.id=cd.destinatario_id
         where
            cd.cliente_id = ?
15:50:32,410 DEBUG AbstractBatcher:424 - preparing statement
15:50:32,410 DEBUG LongType:80 - binding '1' to parameter: 1
15:50:32,426 DEBUG AbstractBatcher:327 - about to open ResultSet (open ResultSets: 0, globally: 0)
15:50:32,426 DEBUG AbstractBatcher:334 - about to close ResultSet (open ResultSets: 1, globally: 1)
15:50:32,426 DEBUG AbstractBatcher:319 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
15:50:32,426 DEBUG AbstractBatcher:470 - closing statement
15:50:32,426 DEBUG SessionImpl:1253 - setting flush mode to: AUTO
Exception in thread "main" java.lang.NullPointerException


[/img]


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

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.