Hi
Here's the situation: I have two tables, MASTER and DETAIL. DETAIL refererring MASTER by a foreign key column MASTER_ID on the primary key of MASTER, wich is MASTER.MASTER_ID. All FK-Columns in our data model are not nullable.
Hibernate version: 3.2.6
Mapping documents:
Mapping in MASTER:
Code:
@Id
@Column(name = "MASTER_ID", nullable = false, precision = 12, scale = 0)
public Long getMasterId() {
return this.masterId;
}
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "MASTER_ID")
@Cascade(CascadeType.ALL)
public List<Detail> getDetails() {
return details;
}
Maping in class Detail:
Code:
@Column(name = "MASTER_ID", nullable = false, precision = 12, scale = 0)
public Long getMasterId() {
return this.masterId;
}
As you can see the mapping in unidirectional.
Now, on calling session.delete(myDetail), the following SQL is generated:
Code:
DEBUG SQL - update DETAIL set MASTER_ID=null where MASTER_ID=?
SET NULL on a NOT NULL-Column is a very bad thing to do!
If i ignore the exception thrown and continue with saving my MASTER, then the correct DELETE statement is generated.
Code:
DEBUG SQL - delete from DETAIL where DETAIL_ID=? and VERSION=?
Now, i tried to be smart by setting the join column to nullable=false:
Code:
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, name = "MASTER_ID")
@Cascade(CascadeType.ALL)
public List<Detail> getDetails() {
return details;
}
Resulting in this at deploy-Time:
Code:
org.hibernate.MappingException: Repeated column in mapping for entity: test.Detail column: MASTER_ID (should be mapped with insert="false" update="false")
Huh ???
I did some research on this error. It might be of importance, that there are several other entities referencing the MASTER, all with a not nullable foreign key from DETAIL2.MASTER_ID or DETAIL3.MASTER_ID on MASTER.MASTER_ID.
AFAIK, Hibernate seems to have a problem with multiple collections sharing the same join column?!
Name and version of the database you are using:
Oracle Server Version : Oracle9i Release 9.2.0.4.0 - Production
I'd be gratefull for any hint. J just want to delete a simple DETAIL...
Bye
Holger