I have a pretty standard master-detail relationship with an indexed collection and composite primary keys:
Code:
@Embeddable
public class InvoiceKey implements Serializable {
private String customer;
private int invoiceNumber;
...
}
Code:
@Embeddable
public class InvoiceRowKey implements Serializable {
private String customer;
private int invoiceNumber;
private int rowNumber;
...
}
Code:
@Entity
public class Invoice {
@Id
private InvoiceKey invoiceKey;
@OneToMany(cascade=CascadeType.ALL)
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@org.hibernate.annotations.IndexColumn(name="rowNumber", base=1)
@JoinColumns({
@JoinColumn(name="customer", referencedColumnName="customer"),
@JoinColumn(name="invoiceNumber", referencedColumnName="invoiceNumber")
})
private List<InvoiceRow> invoiceRows = new ArrayList<InvoiceRow>();
...
}
Code:
@Entity
public class InvoiceRow {
@Id
private InvoiceRowKey orderRowKey;
@ManyToOne
private Invoice invoice;
...
}
The invoice row number is updated nicely but when I remove a row in the middle I get
Code:
Hibernate: update InvoiceRow set customer=null, invoiceNumber=null, rowNumber=null where customer=? and invoiceNumber=? and customer=? and invoiceNumber=? and rowNumber=?
Hibernate: update InvoiceRow set customer=null, invoiceNumber=null, rowNumber=null where customer=? and invoiceNumber=? and customer=? and invoiceNumber=? and rowNumber=?
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
resulting from the nulling of the primary key values in the invoice row.
Should the relation be mapped from the other invoice row side? Some nullable/insertable needed somewhere? I'm on 3.2
Grateful for assistance,
Nik