-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem while loading child objects
PostPosted: Thu Aug 17, 2006 2:06 am 
Beginner
Beginner

Joined: Thu Jun 09, 2005 3:18 am
Posts: 34
Location: India
Hibernate 3.2 cr2

Application Server : JBoss [Zion] 4.0.4.GA

Mapping documents

Parent Mapping file:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="com.infozeal.web.forms.events.EventPostingForm" table="event_main">

<id name="eventId" column="EVNT_ID">
<generator class="increment"/>
</id>


<set name="scheduleSet" inverse="true" lazy="false" cascade="all-delete-orphan">
<key column="EVNT_ID"/>
<one-to-many class="com.infozeal.web.forms.events.EventScheduleForm" />
</set>
<property name="eventTitle" column="EVNT_TITL_TX" type="string" />
</class>

</hibernate-mapping>

Child Mapping file

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.infozeal.web.forms.events.EventScheduleForm" table="event_schedule">

<composite-id>
<key-many-to-one name="eventId" class="com.infozeal.web.forms.events.EventPostingForm" column="EVNT_ID"/>
<key-property name="sequenceNr" column="EVNT_SCHD_SQNC_NR"/>
</composite-id>

<property name="eventDate" column="EVNT_DATE" type="date"/>
</class>

</hibernate-mapping>

Java Code

Event PostingForm eventPostingForm = (EventPostingForm) hibernateSession.createQuery("select eventPostingForm from EventPostingForm eventPostingForm where eventPostingForm.eventId= "+ eventId).uniqueResult();

Set scset = eventPostingForm.getScheduleSet();
Here I am getting the Set size is only 1.

MySQL, version: 5.0.22

I am getting only one child object in Set.

My problem is I want to delete all the child records using Set and insert new child records in to the database.

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 2:29 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Why don't you eagerly fetch the set?

select eventPostingForm from EventPostingForm eventPostingForm left join fetch eventPostingForm.scheduleSet where eventPostingForm.eventId= "+ eventId

Can it be that you only have one entry in the DB?


Maybe you want to try to add methods like addScheduleSet and removeScheduleSet and clearScheduleSet ... with this you could clear your scheduleSet after loading it and add new entries to the collection

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 2:53 am 
Beginner
Beginner

Joined: Thu Jun 09, 2005 3:18 am
Posts: 34
Location: India
Thank you for quick reply

I am having one more child table.

<set name="venueSet" inverse="true" lazy="false" cascade="all-delete-orphan">
<key column="EVNT_ID"/>
<one-to-many class="com.infozeal.web.forms.events.EventVenueForm" />
</set>

I want to load all the parent and child records in one query. Is it possible?

Is it possible to get records only from child table?

Previously i used to load child records in seperate query as follows:

EventScheduleForm scheduleForm = (EventScheduleForm)hibernateSession.createQuery("select scheduleForm from EventScheduleForm scheduleForm where scheduleForm.eventId =" +eventId).uniqueResult;

The above query worked fine when i am using weblogic server and hibernate 3.0.5.

I have unable execute the above query after migrating JBoss application server with hibernate 3.2cr.

I am having more than one records in my DB.

If you could give solution, I am very thankful to you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 3:27 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Of course you can load them all in a query, just add one more left join fetch for that collection

_________________
Please don't forget to rate


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