-->
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: Inheritance Mapping - Concurrency issues
PostPosted: Tue Apr 27, 2004 12:43 pm 
Newbie

Joined: Mon Mar 01, 2004 9:49 pm
Posts: 13
Hi,
I have read the documentation atleast 3-4 times, but couldn't get a nice solution for my problem.

I have two tables tableA and tableB

tableA:
tableA_id
tableA_col1
tableA_col2

and

tableB
tableB_id
tableA_id
tableB_col1
tableB_col2

I have POJOs (ObjectA and ObjectB) representing these two tables. Now my question is,

I want to have ObjectB extenf ObjectA and whenever I create an ObjectB, I want to create ObjectA. If I do it explicitly in my DAO i.e. calling the create for ObjectA and then again use get method to get this Object from database, use the Id of ObjectA and populate objectB.objectAId, then create ObjectB.

But this most likely will cause concurrency issues in my case. because, for ObjectA, ID (which is auto-generated) is the only unique key. UNless otherwise, I know the ID, i can not for sure get the objectA that I just inserted. In hibernate, I can not get the ID, I jsut inserted and hence I am using a getter that gets the latest row in ObjectA and use that ID to insert objectB (Which obviously is not the right way). Anybody ahs any suggestions...?



Whats the best way to solve this.

using version: 2.0.3

my mapping looks like this

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

<hibernate-mapping>
<class name="ObjectA" table="tableA">
<id name="objectAid" column="tableA_id">
<generator class="native"/>
</id>
<property name="column1" column="tableA_col1"/>
<property name="column2" column="tableA_col2"/>
</class>
<class name="ObjectB" table="tableB">
<id name="objectBid" column="tableB_id">
<generator class="native"/>
</id>
<property name="column1" column="tableB_col1"/>
<property name="column2" column="tableB_col2"/>
<property name="objectAId" column="tableA_id"/>
</class>
</hibernate-mapping>
<!-- parsed in 0ms -->


I can use joined-subclass node, but with that node, I dint understand how I can map the objectBId to tableB_Id...

thanks in advance..


Top
 Profile  
 
 Post subject: Hmmm -- several things are missing....
PostPosted: Tue Apr 27, 2004 12:51 pm 
Newbie

Joined: Mon Mar 29, 2004 7:10 pm
Posts: 16
Location: Minneapolis, MN/Topeka, KS
look at the 'subclass' and 'joined-subclass' tags in section 5.1.13 and 5.1.14.

It works very nicely.

-M

_________________
Michael McConnell


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.