-->
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: HQL Query help needed
PostPosted: Mon Jul 02, 2007 7:23 am 
Newbie

Joined: Tue Feb 13, 2007 2:24 am
Posts: 4
Hi,

I have two tables called document and documentattachement. documentattachement table has a foreign key in its documentid column which refers to the document tables's documentid(primary key). So when i load a document object using the HQL, all the documentattachement objects are getting loaded as a collection in the document entity class. But i need only the document objects to get loaded with out the one to many set (which contains the documentattachements for a document) not loaded in the document entity class. For accompolishing this have i to set any parameters in the hbm files or is there any other ways for doing this. I had tried this with many options. But not yet got how to do it. Any help would be really greatful to me.help me to write out this query.

i had provided the hbm files below

document.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 11, 2007 5:51:25 PM by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class name="com.stabilix.felix.dms.entities.Documententity" table="DOCUMENT" >
<id name="documentid" type="long">
<column name="DOCUMENTID" precision="14" scale="0" />
<generator class="increment" />
</id>


<property name="documentversion" type="string">
<column name="DOCUMENTVERSION " />
</property>
<property name="sensitivity" type="string">
<column name="SENSITIVITY" length="50" />
</property>
<property name="createdon" type="timestamp">
<column name="CREATEDON" length="11" />
</property>
<property name="createdbyid" type="string">
<column name="CREATEDBYID" />
</property>
<property name="tite" type="string">
<column name="TITE" />
</property>

<set name="documentattachements" inverse="false">
<key>
<column name="DOCUMENTID" precision="12" scale="0" />
</key>
<one-to-many class="com.stabilix.felix.dms.entities.Documentattachement" />

</set>
</class>
</hibernate-mapping>

documentattachement.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 11, 2007 5:51:25 PM by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class name="com.stabilix.felix.dms.entities.Documentattachement" table="DOCUMENTATTACHEMENT" >
<id name="fileid" type="long">
<column name="FILEID" precision="14" scale="0" />
<generator class="increment" />
</id>
<many-to-one name="document" class="com.stabilix.felix.dms.entities.Documententity" fetch="select">
<column name="DOCUMENTID" precision="12" scale="0" />
</many-to-one>
<property name="filename" type="string">
<column name="FILENAME" />
</property>
<property name="languageid" type="java.lang.Long">
<column name="LANGUAGEID" precision="12" scale="0" />
</property>
<property name="status" type="string">
<column name="STATUS"/>
</property>
</class>
</hibernate-mapping>


Thanks in advance,
Jim


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 8:26 am 
Newbie

Joined: Tue Jun 26, 2007 8:53 am
Posts: 5
Can you please post the query you are using to load the object?

_________________
Thanks,

Shirish

-------------------------------------------

Don't forget to rate, if you are helped.


Top
 Profile  
 
 Post subject: Query help needed
PostPosted: Mon Jul 02, 2007 11:32 pm 
Newbie

Joined: Tue Feb 13, 2007 2:24 am
Posts: 4
Hi,

I tried with the following queries.

1.Documententity instance = (Documententity) HibernateUtil.getCurrentSession()
.get("com.stabilix.felix.dms.entities.Documententity", id);

2.Documententity instance = (Documententity) HibernateUtil.getCurrentSession().createQuery("from com.stabilix.felix.dms.entities.Documententity").uniqueResult();

Both the queries loads the entire object graph. But i need only the documententity class without the one to many(set) not loaded because i need to select only the information from the document table.

Thanks,
Jim


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 03, 2007 2:07 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

Use lazy="true" in set element. So hibernate will load collection at the time actually you use it.


Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 4:53 am 
Newbie

Joined: Tue Feb 13, 2007 2:24 am
Posts: 4
Amila ,Thanks much for your help....


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.