-->
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.  [ 1 post ] 
Author Message
 Post subject: How to use composite-id within inheritance mapping
PostPosted: Thu Nov 12, 2009 7:24 am 
Newbie

Joined: Thu Nov 12, 2009 6:39 am
Posts: 1
Hi All,

I need some help to write my hbm file ,the scenario will be as below:

I have a super class 'A' and subclasses B , C and the Java classes will be as follows:

public abstract class Z{
private String classCode;
//Setter and getter methods
}

public class A extends Z{
private String city;
private String state;
private String name;
//Setter and getter methods

}

public class B extends A{
private String email;
//Setter and getter methods
}

public class C extends A{
private String temp;
//Setter and getter methods
}

Now i have a hibernate mapping file as follows:

<hibernate-mapping>
<class name="A" table="a" abstract="true" proxy="A">
<id name="id" unsaved-value="0">
<generator class="native" />
</id>
<discriminator column="class_code" type="string"/>
<property name="classCode" column="class_code" type="string" insert="false" update="false" />
<property name="name" type="string" column="name" />
<property name="city" type="string" column="city" />
<property name="state" type="string" column="state" />

<subclass name="A" discriminator-value="a" proxy="A">
<property name="email" type="string" column="email" />
</subclass>

<subclass name="B" discriminator-value="b" proxy="B">
<property name="temp" type="string" column="temp" />
</subclass>
</class>
</hibernate-mapping>



Now i want to introduce one more class D which will be something like this :

public class D extends Z{
private String name;
private String description;
private long mappingId;
}
and has a table for this object with primary key 'id' ;

Now i want to have list of Ds for B , C;

so the classes will be modified something like below:

public class B extends A{
private String email;
private List<D> = new ArrayList<D>();
//Setter and getter methods
}

public class C extends A{
private String temp;
private List<D> = new ArrayList<D>();
//Setter and getter methods
}


Now i want have a database design as below:

I should have only one table for 'D' and one table for each Class which will have this D as a list.(for example the classes B and C).Now i have to map these tables as below:

I will have two columns class_code and mapping_id for table 'D' and want to access the rows from this table using the combination of these two fields as a composite key.

Note :-- I don't want to have any extra mapping tables for this mapping .But i want to retrieve the data from table 'D' by using the combination of class_code and mapping_id as a composite key.

Then how can i map this scenario in the given hbm file ? Please help me to solve this.

Thanks in advance
Raj


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.