Hi!
After several hours of trail and error I hope that maybe someone of you can help me with my problem.
I use these simplified mapping files:
father.hbm.xml
Code:
<hibernate-mapping auto-import="true">
<class name="Father" abstract="true">
<id name="id" type="long">
<generator class="native" />
</id>
<discriminator type="string" column="discr" />
<property type="string" name="fathersName" />
</class>
</hibernate-mapping>
brother.hbm.xml
Code:
<hibernate-mapping auto-import="true">
<union-subclass name="Brother" extends="Father" abstract="true">
<property type="string" name="brothersName" />
</union-subclass>
</hibernate-mapping>
sister.hbm.xml
Code:
<hibernate-mapping auto-import="true">
<subclass name="Sister" extends="Father" discriminator-value="sister">
<property type="string" name="sistersName" />
</subclass>
</hibernate-mapping>
and i want to generate with hbm2java this code:
father.java
Code:
public class Father implements java.io.Serializable {
private Long id;
private String fathersName;
public Father() {
}
public Father(Long id) {
this.id = id;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getFathersName() {
return this.fathersName;
}
public void setFathersName(String fathersName) {
this.fathersName = fathersName;
}
}
brother.java
Code:
public class Brother extends Father implements java.io.Serializable {
private String brothersName;
public Brother() {
}
public String getBrothersName() {
return this.brothersName;
}
public void setBrothersName(String brothersName) {
this.brothersName = brothersName;
}
}
sister.java
Code:
public class Sister extends Father implements java.io.Serializable {
private String sistersName;
public Sister() {
}
public String getSistersName() {
return this.sistersName;
}
public void setSistersName(String sistersName) {
this.sistersName = sistersName;
}
}
The result of hbm2ddl should look like this,
Code:
create table Brother (
id int8 not null,
fathersName varchar(255),
brothersName varchar(255),
primary key (id)
);
create table Father (
id int8 not null,
discr varchar(255) not null,
fathersName varchar(255),
sistersName varchar(255),
primary key (id)
);
and that's what I get:
Code:
create table Brother (
id int8 not null,
discr varchar(255) not null,
fathersName varchar(255),
sistersName varchar(255),
brothersName varchar(255),
primary key (id)
);
create table Father (
id int8 not null,
discr varchar(255) not null,
fathersName varchar(255),
sistersName varchar(255),
primary key (id)
);
The classes are generated correct.
But, how can i achieve that the tables Father and Brother are generated the way i need them (no column "sistersName" in table Brother) and how, if its even possible, can i get rid of the "discr" column in the brother table?
cheers,
gekko
Hibernate version: 3