Hello, a newbie-question:
I have a <many-to-one>-association with unique=true. I implemented a HQL-query with a "left join fetch". If no rows found in lookup-table by the first access, hibernate performs an additional select on the lookup-table and fires a ObjectNotFoundException. I expected as result an object-list from the parent-table, even if no dependent rows found in the lookup-table. Where´s my mistake?
Hibernate version: 3.0
Mapping documents:
mapping for the lookup-table:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!-- PKV:LANGTEXTE -->
<class name="com.commerzbank.pkv.business.entity.Paltxt" table="CB.PALTXTVI" lazy="false">
<composite-id>
<key-property name="mandantk" column="MANDANTK" type="string" />
<key-property name="prbdid" column="PRBDID" type="string" />
<key-property name="prbdcoln" column="PRBDCOLN" type="string" />
</composite-id>
<property name="prbdbez" column="PRBDBEZ"/>
</class>
</hibernate-mapping>
mapping for the parent-table:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!-- PKV:ANGEBOTKUNDESEGZUORD -->
<class name="com.commerzbank.pkv.business.entity.Paanks" table="CB.PAANKSVI">
<composite-id >
<key-property name="mandantk" column="MANDANTK" type="string" />
<key-property name="prbnkaid" column="PRBNKAID" type="string" />
<key-property name="kundetyp" column="KUNDETYP" type="string" />
</composite-id>
<many-to-one name="paltxt" class="com.commerzbank.pkv.business.entity.Paltxt"
lazy="true" fetch="join" unique="true" >
<column name="mandantk" />
<column name="kundetyp" />
<formula>'PAANKS'</formula>
</many-to-one>
</class>
</hibernate-mapping>
Name and version of the database you are using: DB2
HQL:
res=sess.createQuery(
"from Paanks paanks left join fetch paanks.paltxt " +
"where paanks.mandantk=:mandantk " +
"and paanks.prbnkaid=:prbnkaid")
.setString("mandantk", entity.getMandantk())
.setString("prbnkaid", entity.getPrbnkaid())
.list();
Debug level Hibernate log excerpt:
DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [com.commerzbank.pkv.business.entity.Paanks#component[mandantk,prbnkaid,kundetyp]{prbnkaid=0000000000001862, kundetyp=2, mandantk=CB}]
DEBUG org.hibernate.event.def.DefaultLoadEventListener - loading entity: [com.commerzbank.pkv.business.entity.Paltxt#component[mandantk,prbdid,prbdcoln]{prbdid=2, prbdcoln=BTYPO, mandantk=CB}]
DEBUG org.hibernate.event.def.DefaultLoadEventListener - attempting to resolve: [com.commerzbank.pkv.business.entity.Paltxt#component[mandantk,prbdid,prbdcoln]{prbdid=2, prbdcoln=BTYPO, mandantk=CB}]
DEBUG org.hibernate.event.def.DefaultLoadEventListener - object not resolved in any cache: [com.commerzbank.pkv.business.entity.Paltxt#component[mandantk,prbdid,prbdcoln]{prbdid=2, prbdcoln=BTYPO, mandantk=CB}]
DEBUG org.hibernate.persister.entity.BasicEntityPersister - Materializing entity: [com.commerzbank.pkv.business.entity.Paltxt#component[mandantk,prbdid,prbdcoln]{prbdid=2, prbdcoln=BTYPO, mandantk=CB}]
DEBUG org.hibernate.loader.Loader - loading entity: [com.commerzbank.pkv.business.entity.Paltxt#component[mandantk,prbdid,prbdcoln]{prbdid=2, prbdcoln=BTYPO, mandantk=CB}]
DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG org.hibernate.SQL - select paltxt0_.MANDANTK as MANDANTK0_, paltxt0_.PRBDID as PRBDID0_, paltxt0_.PRBDCOLN as PRBDCOLN0_, paltxt0_.PRBDBEZ as PRBDBEZ0_0_ from CB.PALTXTVI paltxt0_ where paltxt0_.MANDANTK=? and paltxt0_.PRBDID=? and paltxt0_.PRBDCOLN=?
Hibernate: select paltxt0_.MANDANTK as MANDANTK0_, paltxt0_.PRBDID as PRBDID0_, paltxt0_.PRBDCOLN as PRBDCOLN0_, paltxt0_.PRBDBEZ as PRBDBEZ0_0_ from CB.PALTXTVI paltxt0_ where paltxt0_.MANDANTK=? and paltxt0_.PRBDID=? and paltxt0_.PRBDCOLN=?
DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
DEBUG org.hibernate.type.StringType - binding 'CB' to parameter: 1
DEBUG org.hibernate.type.StringType - binding '2' to parameter: 2
DEBUG org.hibernate.type.StringType - binding 'BTYPO' to parameter: 3
DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
DEBUG org.hibernate.loader.Loader - processing result set
DEBUG org.hibernate.loader.Loader - done processing result set (0 rows)
DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
DEBUG org.hibernate.loader.Loader - total objects hydrated: 0
DEBUG org.hibernate.loader.Loader - done entity load
INFO org.hibernate.event.def.DefaultLoadEventListener - Error performing load command
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.commerzbank.pkv.business.entity.Paltxt#com.commerzbank.pkv.business.entity.Paltxt@3ea520d]
at org.hibernate.ObjectNotFoundException.throwIfNull(ObjectNotFoundException.java:27)
|