I've read this postings:
http://forum.hibernate.org/viewtopic.php?t=549
and i think this IS a bug. To be sure i made a small sample with 3 classes: Person, Vehicle and Car
A Test class shows the behavior. you can switch between the "working" and the "not working" saveOrUpdate with the
static boolean inverse = true|false
here are the classes, ma
package test;
import java.util.Collection;
/**
*
* @hibernate.class table = "person"
*
*/
public class Person {
private String personId;
private String name;
private Collection cars;
/**
* @return
*
* @hibernate.bag cascade = "all" inverse = "true"
* @hibernate.collection-one-to-many class = "test.Car"
* @hibernate.collection-key column = "id_person"
*
*/
public Collection getCars() {
return cars;
}
/**
* @return
*
* @hibernate.property column = "pname"
*/
public String getName() {
return name;
}
/**
* @return
*
* @hibernate.id column = "id_person" generator-class = "uuid.hex"
*/
public String getPersonId() {
return personId;
}
/**
* @param collection
*/
public void setCars(Collection collection) {
cars = collection;
}
/**
* @param string
*/
public void setName(String string) {
name = string;
}
/**
* @param string
*/
public void setPersonId(String string) {
personId = string;
}
}
package test;
/**
*
* @hibernate.class table = "vehicle"
*/
public class Vehicle {
private String vehicleId;
private String serialNumber;
private Person owner;
/**
* @return
*
* @hibernate.property column = "sernum"
*
*/
public String getSerialNumber() {
return serialNumber;
}
/**
* @return
*
* @hibernate.id column = "id_vehicle" generator-class = "uuid.hex"
*/
public String getVehicleId() {
return vehicleId;
}
/**
* @param string
*/
public void setSerialNumber(String string) {
serialNumber = string;
}
/**
* @param string
*/
public void setVehicleId(String string) {
vehicleId = string;
}
/**
* @return
*
* @hibernate.many-to-one column = "id_person" cascade = "all"
*/
public Person getOwner() {
return owner;
}
/**
* @param person
*/
public void setOwner(Person person) {
owner = person;
}
}
package test;
/**
*
* @hibernate.joined-subclass table="cars"
* @hibernate.joined-subclass-key column = "id_vehicle"
*
*/
public class Car extends Vehicle {
private String licensePlate;
/**
* @return
* @hibernate.property column = "licplate"
*/
public String getLicensePlate() {
return licensePlate;
}
/**
* @param string
*/
public void setLicensePlate(String string) {
licensePlate = string;
}
}
//////////////////////////////
// Person.hbm.xml
//////////////////////////////
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="test.Person"
table="person"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="personId"
column="id_person"
type="java.lang.String"
>
<generator class="uuid.hex">
</generator>
</id>
<bag
name="cars"
lazy="false"
inverse="true"
cascade="all"
>
<key
column="id_person"
/>
<one-to-many
class="test.Car"
/>
</bag>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="pname"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Person.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
//////////////////////////////
// Vehicle.hbm.xml
//////////////////////////////
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="test.Vehicle"
table="vehicle"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="vehicleId"
column="id_vehicle"
type="java.lang.String"
>
<generator class="uuid.hex">
</generator>
</id>
<property
name="serialNumber"
type="java.lang.String"
update="true"
insert="true"
column="sernum"
/>
<many-to-one
name="owner"
class="test.Person"
cascade="all"
outer-join="auto"
update="true"
insert="true"
column="id_person"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Vehicle.xml
containing the additional properties and place it in your merge dir.
-->
<joined-subclass
name="test.Car"
table="cars"
dynamic-update="false"
dynamic-insert="false"
>
<key
column="id_vehicle"
/>
<property
name="licensePlate"
type="java.lang.String"
update="true"
insert="true"
column="licplate"
/>
</joined-subclass>
</class>
</hibernate-mapping>
-- **********
-- Person
-- **********
DROP TABLE IF EXISTS person
;
CREATE TABLE person
(
id_person VARCHAR (32) NOT NULL PRIMARY KEY
, pname VARCHAR (255)
)
;
-- **********
-- Vehicle
-- **********
DROP TABLE IF EXISTS vehicle
;
CREATE TABLE vehicle
(
id_vehicle VARCHAR (32) NOT NULL PRIMARY KEY
, id_person VARCHAR (32)
, sernum VARCHAR (255)
)
;
-- **********
-- Car
-- **********
DROP TABLE IF EXISTS cars
;
CREATE TABLE cars
(
id_vehicle VARCHAR (32) NOT NULL PRIMARY KEY
, licplate VARCHAR (255)
)
;