I am ready to bang my head against the wall as i do not understand why this is happening.
I have to mapping files below representing and Entity object and a Release object. Entity has 1 to many relationship with Release.
I am trying to do a query that loads an Entity by Id including all of the related many-to-one associations. I also have a query that loads Release objects as well as Entity associated with a Release with all of the many-to-one associations on the entity.
Here is my issue: When I execute a query(findQuery) in the Release.hbm.xml from a corresponding ReleaseDAO, I get my data with all of the many-to-one's on entity initialized. Here I am happy.
However, when i execute a query(assembleById) within Entity.hbm.xml I get my entity, but all of the many-to-one's are NOT initialized and the debugger shows EnhancedByCGLIB.
Why???
I have tried various combinations and when I copy body of the assembleById query into body of findQuery, then make a call to execute this query on ReleaseDAO, guess what, my entity is loaded with all of the many-to-one associations. I run this via a unit test within eclipse.
My last conclusion and I don't know if I have the energy to look at this any longer, is that there is some jar conflict. If anyone has any idea what is happening, please chime in.
Hibernate guys, any help?
Hibernate version: 2.1.8
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Wed Jan 26 09:44:29 PST 2005 -->
<hibernate-mapping package="foo.domain.release">
<class name="Release"
table="RELEASE"
lazy="true">
<cache usage="transactional"/>
<id name="releaseId" column="RELEASE_ID"
type="java.lang.Integer">
<generator class="sequence">
<param name="sequence">RELEASE_SEQ</param>
</generator>
</id>
<version name="version" column="VERSION"
type="java.lang.Integer" />
<property1 >
<property2 >
<propertyetc >
<many-to-one name="contentType" column="CONTENT_TYPE_ID"
class="foo.domain.lookup.ContentType" not-null="true" />
<many-to-one name="entity" column="ENTITY_ID"
class="foo.domain.types.Entity" not-null="true"/>
<many-to-one name="grade" column="GRADE"
class="foo.domain.lookup.Grade" />
<list name="products" lazy="true" inverse="true"
cascade="all-delete-orphan" table="RELEASE_PRODUCT" batch-size="2">
<key column="RELEASE_ID" />
<index column="ORDERING_NUMBER" />
<one-to-many
class="foo.domain.release.ReleaseProduct" />
</list>
<set name="releaseEvents" lazy="true" inverse="true"
cascade="all-delete-orphan" order-by="EXPECTED_DATE asc"
batch-size="9">
<key column="RELEASE_ID" />
<one-to-many class="foo.domain.release.ReleaseEvent" />
</set>
<bag name="services" lazy="true" cascade="save-update"
table="RELEASE_SERVICE">
<key column="RELEASE_ID" />
<many-to-many class="foo.domain.release.Service"
column="SERVICE"/>
</bag>
</class>
<query name="findQuery">
select release from Release release
left join fetch release.releaseEvents evt
join fetch release.entity entity
left join fetch evt.eventType
left join fetch entity.distributor
left join fetch entity.entityType
left join fetch release.contentType
left join fetch release.entity entity
left join fetch release.grade
left join fetch entity.distributor
where some criteria
</query>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Tue Feb 01 18:41:03 PST 2005 -->
<hibernate-mapping package="foo.domain.types">
<class name="Entity"
table="ENTITY"
discriminator-value="0"
lazy="true">
<cache usage="transactional"/>
<id name="entityId" column="ENTITY_ID"
type="java.lang.Integer">
<generator class="sequence">
<param name="sequence">ENTITY_SEQ</param>
</generator>
</id>
<discriminator column="CONTENT_TYPE_ID"
type="java.lang.Integer" />
<version name="version" column="VERSION"
type="java.lang.Integer" />
<property name="entityName" column="ENTITY_NAME"
type="java.lang.String" not-null="true" />
<many-to-one name="contentType" column="CONTENT_TYPE_ID"
class="foo.domain.lookup.ContentType" not-null="true"
insert="false" update="false" />
<many-to-one name="distributor" column="DISTRIBUTOR_ID"
class="foo.domain.lookup.Distributor" />
<many-to-one name="entityType" column="ENTITY_TYPE_ID"
class="foo.domain.lookup.EntityType" not-null="true" />
</class>
<query name="assembleById">
from Entity entity
left join fetch entity.contentType
left join fetch entity.distributor
left join fetch entity.entityType
left join fetch entity.relatedChildren
where entity.entityId = :entityId
</query>
</hibernate-mapping>
All of the many-to-one objects are mapped as lazy
Code between sessionFactory.openSession() and session.close():
The above queries are called from within DAO's, I have other stuff working just fine.
Full stack trace of any exception that occurs:
No exceptions here, just straight sql which I run against a database and all information I need is retrieved
Name and version of the database you are using:
Oracle 9.2.0.26
|