Specifically with our database relationship being like so, title:
Table S
column id
...other irrelevant columns omitted...
primary key on id only
Table C
column S_id
column id
...
compound primary key on S_id (which is a foreign key to id column in table S) and id.
Table I
column S_id
column id
column C_id
...
compound primary key again on S_id and id.
compound foreign key on C_id and S_id, but C_id column in this table is also nullable.
I have attempted the following for java hibernate annotations on IObject for modeling table I:
@ManyToOne
@JoinColumns({
@JoinColumn({name="C_id", referencedColumnName="id",insertable=false,updateable=false),
@JoinCOlumn({name="S_id", referencedColumnName="S_id", insertable=false,updateable=false)
})
private CObject _cObjectRef;
@EmbeddedId
private EmbeddedIdCompositeKeyObject _primaryKey;
...
Here is the important parts of java hibernate annotations on CObject for modeling table C:
@EmbeddedId
private EmbeddedIdCompositeKeyObject _primaryKey;
@MapsId("_s_id")
@ManyToOne(optional=false)
@JoinColumn(name="S_id", nullable = false)
private SObject _sObject;
...
And here is what EmbeddedIdCompositeKeyObject looks like (its @Embeddable and implements Serializable):
@Column(name = "id", nullable = false)
private int _id;
@Column(name = "S_id", nullable = false)
private int _s_id;
...
constructors, getters, hashCode, and equals ommitted.
However, when run, hibernate fails to update these columns of table I despite the _cObject being set to an existing CObject instance that matches what exists in the database. Every other column in the I object table saves and updates correctly upon calling hibernate's session.saveOrUpdate method on IObject except one where this nullable compound foreign key is used.
I have tried removing insertable and updateable qualifiers on the JoinColumns, or adding them in different combinations of true or false, and even mixing nullable in, however when that is attempted errors such as the following appear:
Mixing nullable and non nullable columns in a property is not allowed
(this seems like what I need though)Mixing updatable and non updatable columns in a property is not allowed
Mixing insertable and non insertable columns in a property is not allowed
Repeated column in mapping for entity: foo.bar.IObject columns S_id (should be mapped with insert="false" update="false"
Adding @MapsId("_s_id") to IObject's CObject reference doesn't appear to make a difference.
This question is somewhat similar to another and almost exactly like another, however neither questions appear to ask about cases with nullable composite foreign keys with primary key overlap, and none of the proposed solutions appear to work for this case, either.