-->
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: joined-subclass saving supercalss data
PostPosted: Sat Apr 11, 2009 10:04 pm 
Newbie

Joined: Sun Feb 18, 2007 1:05 pm
Posts: 16
Hi,
I have a class hierarchi. ie A extends B
Now I have two tables A_TABLE and B_TABLE . A_TABLE is mapped to A and B_TABLE IS mapped to B using joined-subclass tag

i.e my a.hbm.xml look like


Code:
<?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 Sep 3, 2008 3:42:54 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="A" table="A_TABLE" >
        <id name="aId" type="int">
            <column name="A_ID" />
            <generator class="identity" />
        </id>
       /* A's properties follows here */

    <joined-subclass name="B table="B_TABEL" >
           <key column="A_ID"/>
           /* B's properties follows here */
    </joined-subclass>

</hibernate>





Now the issue is , when I save B ie when I call session.save (b's object) a new record is getting inserted for A also .i.e new record is inserting into A_TABLE.
How can I restrict A getting saved when I save B ?
Is there anything missing in what I did ? Or is it completey wrong to use "table per concrete class " aproach here ?

Thanks in advance.

Shaiju


Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 12, 2009 12:23 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
First of all, the approach you are following is not "table per concrete class", this is "Table per Subclass approach". and it works in same way what you saw.

You can eliminate the problem what you mentioned ( don't want to save object of superclass) by using "Table Per Concrete class with explicit polymorphism".

For that you have to change
Quote:
<joined-subclass ....../> to <union-subclass............./>


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.