Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0.5
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="ENTITY" batch-size="50" name="Entity">
<cache usage="read-write"/>
<id unsaved-value="-1" name="id" column="ID">
<generator class="increment"/>
</id>
<set cascade="all-delete-orphan" where="DISCRIMINATOR = 1" table="ATTRIBUTERELATIONSHIP" name="stringAttributes">
<key not-null="true" column="ENTITYID"/>
<one-to-many class="StringAttribute"/>
</set>
<set cascade="all-delete-orphan" where="DISCRIMINATOR = 2" table="ATTRIBUTERELATIONSHIP" name="integerAttributes">
<key not-null="true" column="ENTITYID"/>
<one-to-many class="IntegerAttribute"/>
</set>
<set cascade="all-delete-orphan" where="DISCRIMINATOR = 3" table="ATTRIBUTERELATIONSHIP" name="dateAttributes">
<key not-null="true" column="ENTITYID"/>
<one-to-many class="DateAttribute"/>
</set>
<set cascade="save-update" table="ENTITYCLASSIFICATION" name="entityClasses">
<key not-null="true" column="ENTITYID"/>
<many-to-many class="EntityClass" column="CLASSID"/>
</set>
<set cascade="all" table="RELATES" name="relationsIn">
<key not-null="true" column="ENTITYID2"/>
<one-to-many class="Relationship"/>
</set>
<set cascade="all" table="RELATES" name="relationsOut">
<key not-null="true" column="ENTITYID1"/>
<one-to-many class="Relationship"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Criteria criteria = session.createCriteria(Entity.class, "entity")
.setFetchMode("stringAttributes", FetchMode.JOIN)
.setFetchMode("integerAttributes", FetchMode.JOIN)
.setFetchMode("dateAttributes", FetchMode.JOIN)
.setFetchMode("relationsIn", FetchMode.SELECT)
.setFetchMode("relationsOut", FetchMode.SELECT)
.add(Restrictions.in("entity.id", ids))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
List resultList = criteria.list();
Full stack trace of any exception that occurs:N/A
Name and version of the database you are using:Mysql 4.1.12
The generated SQL (show_sql=true):Code:
Hibernate: select this_.ID as ID3_, stringattr2_.ENTITYID as ENTITYID5_, stringattr2_.ID as ID5_, stringattr2_.ID as ID0_, stringattr2_.ATTRIBUTECLASSID as ATTRIBUT3_2_0_, stringattr2_.INSERTIONDATE as INSERTIO4_2_0_, stringattr2_.STARTDATE as STARTDATE2_0_, stringattr2_.STOPDATE as STOPDATE2_0_, stringattr2_.VALUEID as VALUEID2_0_, integeratt3_.ENTITYID as ENTITYID6_, integeratt3_.ID as ID6_, integeratt3_.ID as ID1_, integeratt3_.ATTRIBUTECLASSID as ATTRIBUT3_2_1_, integeratt3_.INSERTIONDATE as INSERTIO4_2_1_, integeratt3_.STARTDATE as STARTDATE2_1_, integeratt3_.STOPDATE as STOPDATE2_1_, integeratt3_.VALUEID as VALUEID2_1_, dateattrib4_.ENTITYID as ENTITYID7_, dateattrib4_.ID as ID7_, dateattrib4_.ID as ID2_, dateattrib4_.ATTRIBUTECLASSID as ATTRIBUT3_2_2_, dateattrib4_.INSERTIONDATE as INSERTIO4_2_2_, dateattrib4_.STARTDATE as STARTDATE2_2_, dateattrib4_.STOPDATE as STOPDATE2_2_, dateattrib4_.VALUEID as VALUEID2_2_ from ENTITY this_ left outer join ATTRIBUTERELATIONSHIP stringattr2_ on this_.ID=stringattr2_.ENTITYID and stringattr2_.DISCRIMINATOR = 1 and stringattr2_.DISCRIMINATOR='1' left outer join ATTRIBUTERELATIONSHIP integeratt3_ on this_.ID=integeratt3_.ENTITYID and integeratt3_.DISCRIMINATOR = 2 and integeratt3_.DISCRIMINATOR='2' left outer join ATTRIBUTERELATIONSHIP dateattrib4_ on this_.ID=dateattrib4_.ENTITYID and dateattrib4_.DISCRIMINATOR = 3 and dateattrib4_.DISCRIMINATOR='3' where this_.ID in (?, ?, ?, ?, ?, ?, ?)
Hibernate: select attributec0_.ID as ID0_, attributec0_.NAME as NAME7_0_ from ENTITYCLASS attributec0_ where attributec0_.ID in (?, ?, ?, ?)
Hibernate: select stringvalu0_.ID as ID0_, stringvalu0_.VALUE as VALUE3_0_ from STRINGATTRIBUTE stringvalu0_ where stringvalu0_.ID in (?, ?, ?, ?, ?, ?, ?)
My problem is simple (i think), some subselects don't seem to be happening in my Criteria query. As you can see, the stringattribute JOIN takes place, and subsequent queries to the STRINGATTRIBUTE value table are called, but the RELATES subselect queries are never executed. What am I missing?
Thanks,
Jason