-->
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.  [ 8 posts ] 
Author Message
 Post subject: How to disable fetching assocaited objects
PostPosted: Mon Oct 11, 2004 4:20 am 
Newbie

Joined: Mon Oct 11, 2004 4:08 am
Posts: 15
Hibernate version:2.1.6

Mapping documents:<class name="A" table="PB_ROLE" dynamic-update="true" dynamic-insert="true">
<id name="roleID" column="ROLE_ID">
<generator class="assigned"/>
</id>
<property name="description" column="DESCRIPTION" />
<many-to-one name="b" class="com.shk.jaf.application.security.service
.domain.impl.Role" column="ROLE_ID_FK" unique="true" />
</class>


Code between sessionFactory.openSession() and session.close():
Role rr = (Role) session.createCriteria(A.class)
.add(Expression.eq("roleID", new Integer(2)))
.uniqueResult();


Full stack trace of any exception that occurs:

Name and version of the database you are using:Oracle 9i

The generated SQL (show_sql=true):select this.ROLE_ID as ROLE_ID1_, this.DESCRIPTION as DESCRIPT2_1_, t
his.ROLE_ID_FK as ROLE_ID_FK1_, role1_.roleID as roleID0_, role1_.name as name0_
, role1_.created_On as created_On0_, role1_.created_By as created_By0_, role1_.u
pdated_On as updated_On0_, role1_.updated_By as updated_By0_ from PB_ROLE this,
Role role1_ where this.ROLE_ID=? and this.ROLE_ID_FK=role1_.roleID(+)


Debug level Hibernate log excerpt:

I have a object A with B associated object. However, I don't want to query A object and the Hibernate automatically fetch B Object.

How can I control fetching on all assoicated object (one-to-one, one-to-many )?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 4:23 am 
Newbie

Joined: Mon Oct 11, 2004 4:08 am
Posts: 15
In addition, I have tried set the property "hibernate.max_fetch_depth" to 0, but Hibernate still query the associated object with another SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 5:06 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Use lazy=true on the many side (set, bag, list ... but not array).

BTW: This is a RTM question.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 5:20 am 
Newbie

Joined: Mon Oct 11, 2004 4:08 am
Posts: 15
I knew only for one-to-many or many-to-many not for one-to-one or many-to-one. Besides, I also tried to .setFetchMode("b", FetchMode.LAZY), Hibernate also still gets "b" automatically with using another SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 5:26 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Please show the mapping files.

Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 5:59 am 
Newbie

Joined: Mon Oct 11, 2004 4:08 am
Posts: 15
Please see the first message


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 6:03 am 
Newbie

Joined: Thu Sep 25, 2003 7:21 pm
Posts: 17
http://www.hibernate.org/162.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 6:14 am 
Newbie

Joined: Mon Oct 11, 2004 4:08 am
Posts: 15
I tried your suggestion but the result is same that Hibernate still gets associated object "b" by usign another SQL as below:

Mapping
======
<class name="A" table="PB_ROLE" dynamic-update="true" dynamic-insert="true">
<id name="roleID" column="ROLE_ID">
<generator class="assigned"/>
</id>
<property name="description" column="DESCRIPTION" />
<many-to-one name="b" class="com.shk.jaf.application.security.service
.domain.impl.Role" column="ROLE_ID_FK" unique="true" outer-join="false" />
</class>

SQL
===
Hibernate: select this.ROLE_ID as ROLE_ID0_, this.DESCRIPTION as DESCRIPT2_0_, t
his.ROLE_ID_FK as ROLE_ID_FK0_ from PB_ROLE this where this.ROLE_ID=?
Hibernate: select role0_.roleID as roleID0_, role0_.name as name0_, role0_.creat
ed_On as created_On0_, role0_.created_By as created_By0_, role0_.updated_On as u
pdated_On0_, role0_.updated_By as updated_By0_ from Role role0_ where role0_.rol
eID=?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.