@ManyToOne+@JoinColumn Error
djabornig Jan 19, 2010 2:58 PMI try to delete an entity with an unidirectional OneToMany Relationship mapped like this:
@Entity
@Table(name = "TEST_SOURCE_ENTITY")
@Audited
public class SourceEntity extends GenericEntity<Long> {
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "SOURCE_ENTITY_UNI_ID")
@Cascade(value = { org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@org.hibernate.annotations.IndexColumn(name = "SOURCE_ENTITY_UNI_IDX")
@AuditJoinTable(name = "TEST_SOURCE_TARGET_ENTITY_AUD")
private List<TargetEntity> unidirectionalTargetEntities = new ArrayList<TargetEntity>();
public List<TargetEntity> getUnidirectionalTargetEntities() {
return unidirectionalTargetEntities;
}
public void setUnidirectionalTargetEntities(
List<TargetEntity> unidirectionalTargetEntities) {
this.unidirectionalTargetEntities = unidirectionalTargetEntities;
}
}
@Entity
@Table(name = "TEST_TARGET_ENTITY")
@Audited
public class TargetEntity extends GenericEntity<Long> {
private static final long serialVersionUID = 1L;
}
On delete envers tries to set a null value on the inverse join column.
SourceEntity sourceEntity = ... session.delete(sourceEntity);
And this exception is the result...
Caused by: java.sql.BatchUpdateException: ORA-01400: Einfügen von NULL in ("TEST"."TEST_SOURCE_TARGET_ENTITY_AUD"."ID") nicht möglich
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10768)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:231)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 49 more
I tried already a lot of things and if i make the relationship bidirectional it seems to work.
The same issue occurs if i map the relationship with @OneToMany+@JoinColumn on the one side, and @ManyToOne+@JoinColumn(insertable=false, updatable=false)
What am i doing wrong here? I'm using the current envers 1.2.2. in the maven repo.