When using the following mappings:
@Entity
@Audited
public class Customer {
@Id
private Integer id;
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "customerId", foreignKey = @ForeignKey(name = "FK_CUSTOMER_ADDRESS")
private List<CustomerAddress> addresses;
}
@Entity
@Audited
public class Address {
@Id
private Integer id;
}
@Embeddable
public class CustomerAddressId implements Serializable {
@ManyToOne
private Address address;
@ManyToOne
private Customer customer;
}
@Entity
@Audited
public class CustomerAddress {
@EmbeddedId
private CustomerAddressId id;
}
If a user attempts to remove the associated CustomerAddress and Address rows from the database, a constraint violation is thrown. The XML mapping for CustomerAddress looks like:
As is evident, the foreign-key="none" is specified for the relationship between CustomerAddress's audit table and the Address and Customer entities. But despite specifying that, the DDL generates a foreign key anyway:
|