
| Key: |
HHH-3108
|
| Type: |
Bug
|
| Status: |
Open
|
| Priority: |
Minor
|
| Assignee: |
Unassigned
|
| Reporter: |
Marcin Mościcki
|
| Votes: |
1
|
| Watchers: |
1
|
|
If you were logged in you would be able to see more operations.
|
|
|
|
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)
|
|
Description
|
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) |
Show » |
|
I meant here that there is no exception thrown - the collection returned is incorrectly empty, but I believe there already is a bug report on that.