Getting invalid ID on cascade (using @DiscriminatorColumn)
----------------------------------------------------------
Key: HHH-6905
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6905
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 4.0.0.CR4
Environment: JPA 2 / Hibernate 4.0.0.CR4, Postgres 9, Linux (Ubuntu 11.10)
Reporter: Rogério Lino
Priority: Minor
When try to persist a entity with a list (@OneToMany), the id returned to save in cascade
is the value of discriminator column (int).
Ex:
@Entity
@Table(name = "person")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType =
DiscriminatorType.INTEGER)
class Person extends MappedSuperClassWithId {
}
----
@Entity
@DiscriminatorValue("9999")
class Employee extends Person {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "employee")
private List<Phone> phones;
}
----
Employee employee = new Employee();
// employee setters
Phone phone = new Phone();
// employee setters
employee.getPhones().add(phone);
entityManager.persist(employee);
// throw org.hibernate.exception.ConstraintViolationException
// ERROR: insert or update on table "phone" violates foreign key constraint
"..."
// Detail: Key (id_employee)=(9999) is not present in table "person".
----
The column order in the table person (generated by hibernate.hbm2ddl.auto) is
"type" and "id". When I change to "id" and "type",
works fine.
For some reason Hibernate is getting as last id the value of first table column.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira