[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3108) <load-collection role="entity_name.property"> doesn't work

Marcin Mościcki (JIRA) noreply at atlassian.com
Fri Mar 14 12:21:33 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3108?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_29801 ] 

Marcin Mościcki commented on HHH-3108:
--------------------------------------

Ok, I think I fixed it:
In org.hibernate.cfg.ResultSetMappingBinder, the entity name of the parent side of the relationship was automatically
prefixed with default package:

    String ownerClassName = HbmBinder.getClassName(collectionAttribute.substring( 0, dot ), mappings );

I changed this to:
		String ownerClassName = collectionAttribute.substring( 0, dot );
		if (mappings.getClass(ownerClassName)==null) {
			ownerClassName = HbmBinder.getClassName( ownerClassName, mappings );
		}

Below there's a comment:
		//FIXME: get the PersistentClass
		java.util.Map propertyResults = bindPropertyResults(alias, returnElem, null, mappings );

which might have alluded to this, or some other issue, I don't know.
Changed file attached - I used official 3.2.6.ga version available in bundled distribution - if you'd like a patch, please let me know to which tag.


> <load-collection role="entity_name.property"> doesn't work
> ----------------------------------------------------------
>
>                 Key: HHH-3108
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3108
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: metamodel
>    Affects Versions: 3.2.6
>         Environment: Hibernate 3.2.6, Oracle 9 (insignificant)
>            Reporter: Marcin Mościcki
>            Priority: Minor
>         Attachments: hibernatebug.zip
>
>
> I use an <sql-query> for a <loader> in a collection owned by a named entity. The role attribute is set to "<entity-name>.<property-name>" - exactly the key under witch the collection's meta data is registered in SessionFactoryImpl.collectionPersisters map - but when the query is being added, SessionFactoryImpl looks for it under the key "<package>.<entity-name>.<property-name>" in this map, and doesn't find it.
> When entity-name attribute is removed from the entity mapping and unqualified class name is used to refer to it instead, everything works fine.
> The easiest, and probably most uniform solution would be to introduce a second attribute "entity-role" to the load-collection element.
> The following exception results from mapping:
> <hibernate-mapping package="hibernatedemo.model">
> ....
> <class table="persons_test" entity-name="person" name="Person">
> ....
>         <set name="personMap" inverse="true">
> 			<key/>
> 			<one-to-many entity-name="person_map"/>
> 			<loader query-ref="fetch_person_map_by_person"/>
> 		</set>
> </class>
> 	<sql-query name="fetch_person_map_by_person">
>     	<load-collection alias="map" role="person.personMap" />
> 		select {map.*} from persons_map_test map where map.person_id=:id
> 	</sql-query>
> org.hibernate.MappingException: Unknown collection role: hibernatedemo.model.person.personMap
> 	at org.hibernate.impl.SessionFactoryImpl.getCollectionPersister(SessionFactoryImpl.java:558)
> 	at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.addCollection(SQLQueryReturnProcessor.java:370)
> 	at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processCollectionReturn(SQLQueryReturnProcessor.java:405)
> 	at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:335)
> 	at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:148)
> 	at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:64)
> 	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:446)
> 	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:352)
> 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
> 	at hibernatedemo.Test.getHibernateSession(Test.java:44)
> 	at hibernatedemo.Test.main(Test.java:25)
> 	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:324)
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

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