-->
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.  [ 2 posts ] 
Author Message
 Post subject: Intializing the list of a detached object before updating
PostPosted: Sun Feb 15, 2009 7:14 am 
Newbie

Joined: Sun Feb 15, 2009 7:06 am
Posts: 2
Hi!
Given objects my.domain.ObjectA and my.domain.ObjectB. They have a many-to-one relation, where ObjectA contains a List of ObjectB, and ObjectB contains a reference to ObjectA. It's mapped like this:

Code:
<class name="my.domain.ObjectA" table="TABLE_A">
  <id name="id" type="java.lang.Long" access="field">
    <column name="IDE_TABLE_A" precision="9" scale="0" />
    <generator class="identity" />
  </id>
  <bag name="listOfObjectB" inverse="true" cascade="save-update, delete">
    <key>
      <column name="IDE_TABLE_A" not-null="true" />
    </key>
    <one-to-many class="my.domain.ObjectB" />
  </bag>
</class>


Code:
<class name="my.domain.ObjectB" table="TABLE_B">
  <id name="id" type="java.lang.Long" access="field">
    <column name="IDE_TABLE_B" precision="9" scale="0" />
    <generator class="identity" />
  </id>
  <many-to-one name="objectA" class="my.domain.ObjectA">
    <column name="IDE_TABLE_A" />
  </many-to-one>
</class>


Now for the question: A service class receives as input a detached ObjectA, where the listOfObjectB may be null, even if the database TABLE_B contains rows with FK relations to rows in TABLE_A. Now, before manipulating and calling saveOrUpdate() on the ObjectA instance, I would like to make sure that the listOfObjectB is loaded and initialized with the correct data from TABLE_B. What would be the best way to do this?

Be aware that the data in the instance of ObjectA may be different from the data in TABLE_A, so I do not want to load ObjectA again. I only want to load the list of ObjectBs.


Top
 Profile  
 
 Post subject: A query to get the collection 'listOfObjectB'
PostPosted: Mon Feb 16, 2009 11:50 am 
Newbie

Joined: Mon Sep 18, 2006 11:15 am
Posts: 6
If you want to get the list you could use a query to get the collection from the database.

e.g. HQL like the following :
Code:
select elements(objectA.listOfObjectB) from ObjectA objectA where objectA.id = ?


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