Hi,
I have a table "Attribute". Attributes can be of kind main, sub or single. Main and sub attributes should be in relation with each other. So I defined a mainAttribute which should be filled when it is a sub attribute.
When I build my attribute set I assign the main attribute object to the mainAttribute member. When I try to insert this, I get: ORA-02291: integrity constraint (USR.FK955EEBD5F5D4109C) violated - parent key not found
I don't know which Ids are set, because this happens in the insert method of hibernate. Can I somehow log the parameters, after the Ids are filled by hibernate?
Is my understanding how to handle such a relation correct or should I modfy my ER-Model? Can such thing modelled into one table?
Code:
public class Attribute implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = -4735854874205612593L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name="attribute_code", length=5)
private String attributeCode;
@Column(name="attribute_kind", length=20)
private String attributeKind;
@GeneratedValue (generator = "fkMainAttributeGenerator")
@org.hibernate.annotations.GenericGenerator(name=
"fkMainAttributeGenerator", strategy = "foreign", parameters={
@Parameter(name="property", value="mainAttribute")})
@Column (name = "main_attribute_id")
private long mainAttributeId;
@ManyToOne (targetEntity = Attribute.class)
@JoinColumn (name = "main_attribute_id", insertable = false, updatable = false)
private Attribute mainAttribute;
@Column(name="description")
private String description;
@Column(name="currency", length=5)
private String currency;
@Column(name="amount")
private Float amount;
@Column(name="attribute_date", length=50)
private String attributeDate;
@Column(name="rate_count")
private int rateCount;
@Column(name="rate_kind")
private String rateKind;
@Column(name="account_number", length=20)
private String accountNumber;
@Column(name="attribute_text")
private String attributeText;
@Column(name="text")
private String text;
@Column(name="negative")
private boolean negative;
@ManyToOne (targetEntity = Data.class, fetch = FetchType.LAZY)
@JoinColumn (name = "_data_id")
private Data Data;