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..
|