[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2745) NullPointerException when eager fetching joined many-to-many with native SQL query

Mihail Fridliand (JIRA) noreply at atlassian.com
Thu Jul 26 06:42:52 EDT 2007


NullPointerException when eager fetching joined many-to-many with native SQL query
----------------------------------------------------------------------------------

                 Key: HHH-2745
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2745
             Project: Hibernate3
          Issue Type: Bug
          Components: core
    Affects Versions: 3.2.1
         Environment: Hibernate 3.2.1, DB2
            Reporter: Mihail Fridliand



NullPointerException when joining many-to-many assoziation with native SQL query:
	
	java.lang.NullPointerException
	at org.hibernate.loader.custom.sql.SQLQueryParser.resolveProperties(SQLQueryParser.java:182)
	at org.hibernate.loader.custom.sql.SQLQueryParser.resolveCollectionProperties(SQLQueryParser.java:135)
	at org.hibernate.loader.custom.sql.SQLQueryParser.substituteBrackets(SQLQueryParser.java:98)
	at org.hibernate.loader.custom.sql.SQLQueryParser.process(SQLQueryParser.java:51)
	at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:110)
	at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:43)
	at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:114)
	at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:444)
	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:351)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
	
The	SQLQueryReturnProcessor ignores many-to-many assoziations:

private void addCollection(String role, String alias, Map propertyResults) {
		SQLLoadableCollection collectionPersister = ( SQLLoadableCollection ) factory.getCollectionPersister( role );
		alias2CollectionPersister.put( alias, collectionPersister );
		String suffix = generateCollectionSuffix();
		log.trace( "mapping alias [" + alias + "] to collection-suffix [" + suffix + "]" );
		alias2CollectionSuffix.put( alias, suffix );
		collectionPropertyResultMaps.put( alias, propertyResults );

		if ( collectionPersister.isOneToMany() ) {
			SQLLoadable persister = ( SQLLoadable ) collectionPersister.getElementPersister();
			addPersister( alias, filter( propertyResults ), persister );
		}
	}

Mapping of a many-to-many:


<hibernate-mapping>
 	<class name="A" table="A" schema="TEST" >      
         <set name="manyToMany" inverse="true" table="AC" >
           	<key>
               	<column name="A_OID" not-null="true" />
          	</key>
       	 	<many-to-many class="C">
            	 <column name="C_OID" not-null="true" />
       		</many-to-many>
     
      	</set>
   </class>

   <class name="C" table="C" schema="TEST">     
   </class>
  
   <resultset name="AandC">
		  <return alias="a" class="A"/>
   		  <return-join alias="c" property="a.manyToMany"/>
   </resultset>
	
	 <sql-query  name="getAandC"  resultset-ref="AandC" >
         <![CDATA[
          	select DISTINCT {a.*},{c.*} from  A a join AC ac on a.OID = ac.A_OID join C c on c.C_OID=ac.C_OID
         ]]>
	</sql-query>
	  
</hibernate-mapping>

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list