-->
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: Need Your Help: Hibernate Inheritance Mapping..
PostPosted: Thu Oct 16, 2008 2:58 pm 
Newbie

Joined: Thu Oct 16, 2008 2:49 pm
Posts: 3
Hi All,

This question is regardig 'Table per class hierarchy' mapping.

I have a class A.
I have a class B extends A.
I have only one table (say T1) in the database for both A and B.


class A {
private String a1;
private String a2;
private String a3;

// Setters and Getters here
}


class B extends A {
private String b1;
// Setters and Getters here
}


Table T1 has columns as follows:

A1_COL VARCHAR2(10) PK
A2_COL VARCHAR2(10)
A3_COL VARCHAR2(10)
B1_COL VARCHAR2(10)

Suppose T1 has a row like this:

100 200 300 null


<hibernate-mapping>
<class name="foo.A" discriminator-value="0" table="T1">

<id name="id" column="A1_COL">
<generator class="sequence">
<param name="sequence">SEQ_A1</param>
</generator>
</id>

<discriminator column="DISCRIM_A1" />
............
............

<subclass name="foo.B" discriminator-value="17">
<property name="b1" column="B1_COL" type="string"/>
</subclass>
</class>
</hibernate-mapping>



Using Hibernate program I need to do the following task:

1) Retrieve the row based on primary key (100).
2) Set "B1_COL" value to 500 instead of null.
3) Update the database with new values.

I mean the above program should result in the following row in Database.

100 200 300 500


Appreciate your quick help.
This might be simple question, but i am new to Hibernate, so kindly help me.

Thanks n Have a nice day,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 20, 2008 5:23 am 
Newbie

Joined: Mon Oct 20, 2008 5:22 am
Posts: 6
Looks like, in your example you are missing discriminator column (DISCRIM_A1) in the table.

Cheers,
Kiran


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.