-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Many-to-one initialization issues
PostPosted: Wed Jun 22, 2005 9:19 pm 
Beginner
Beginner

Joined: Mon Jan 24, 2005 6:42 pm
Posts: 26
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 22, 2005 10:02 pm 
Beginner
Beginner

Joined: Mon Jan 24, 2005 6:42 pm
Posts: 26
To follow-up on this, it seems I overlooked a step when running into this issue.

I run two queries in the same transaction:

First query retrieves an Entity by a specific field, without initializing any of the many-to-one objects.

The second query is the query I specified in the first message, it tries to initialize many-to-one's, but looking at the debugger does not.

All of the many-to-ones are defined as <cache usage="transactional"/>

Then only thing I can think of is that all of the many-to-one's are cached as proxies?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 12:31 pm 
Beginner
Beginner

Joined: Mon Jan 24, 2005 6:42 pm
Posts: 26
So does anyone have comments on this? I still don't understand why I am seeing the result above.

This morning I tried the following:

Run 1st query that does not initialize many-to-ones
call HibernateUtil.getSession().clear()

Run 2nd query that does initialize many-to-ones
All my many-to-ones are inititalized as expected.

So basically the cache gets cleared if my understanding is correct and I start fresh.

My question still remains why do the uninitialized many-to-ones stay that way even though my second query is supposed to initialize them?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 12:53 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
If you don't stop bumping up your posting every few hours I'll ban you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 1:24 pm 
Beginner
Beginner

Joined: Mon Jan 24, 2005 6:42 pm
Posts: 26
Christian, I didn't know that posting more detail was considered bumping.

Per your own rules:
Don't "bump up" your posting. Don't ask why nobody answers you every other hour, simply follow the steps outlined here. Moderators will very likely delete your "bump" right away.


Per your own rules I have tried to provide as much data as possible so I could get some kind of a response. It has taken me almost a week to get to the point of posting.

The only type of response I can get is that I am bumping up my post??? Is this for real. Is this the type of help I should expect when we are actually paying for support?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.