-->
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: Problem with table per concrete class
PostPosted: Mon Jun 20, 2005 12:41 pm 
Newbie

Joined: Mon Jun 20, 2005 12:20 pm
Posts: 17
Hi all,

I try to use Hibernate 3.0.5 to map inherited class with the method describled in the document "10.1.5. Table per concrete class". However, Hibernate always creates a table for my parent abstract class. Here is my sampe java code and mapping xml:

[code]
public abstract class Property {
protected long propertyId;
protected String name;

public long getPropertyId() {
return propertyId;
}

public void setPropertyId(long propertyId) {
this.propertyId = propertyId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

abstract Object getPropertyValue();
}

public class StringProperty extends Property {
String value;

Object getPropertyValue() {
return value;
}
}

public class DateProperty extends Property {
Date value;

Object getPropertyValue() {
return value;
}
}

<class name="Property">
<id name="propertyId" column="property_id" unsaved-value="0">
<generator class="increment"/>
</id>
<property name="name" column="name" type="string" />

<union-subclass name="StringProperty" table="string_property">
<property name="value" column="value" type="string" />
</union-subclass>

<union-subclass name="DateProperty" table="date_property">
<property name="value" column="value" type="date" />
</union-subclass>
</class>

[/code]

Hibernate generates the following result:

create table Property (
property_id bigint not null,
name varchar(255),
primary key (property_id)
);

create table date_property (
property_id bigint not null,
name varchar(255),
value date,
primary key (property_id)
);

create table string_property (
property_id bigint not null,
name varchar(255),
value varchar(255),
primary key (property_id)
);


According to the docuemntation, it should have only 2 tables. Has anyone any idea? Thanks in advance!


Top
 Profile  
 
 Post subject: try making it abstract
PostPosted: Thu Jun 23, 2005 4:26 pm 
Beginner
Beginner

Joined: Thu Jun 23, 2005 4:11 pm
Posts: 24
You have three concrete classes, you can make a class abstract="true"


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.