It's not too hard to find good examples on how to do this with OneToOne, but the same tactic doesn't work for me in Hibernate on a OneToMany.
I have 2 objects, both of which are subclassed from a base object type which has a composite primary key. The key is in the form (string, integer).
the common base class for these entities is using an embeddedId class. The actual columns of interest are:
And in the child entity:
A reasonably intuitive mapping would be:
However, that will fail because you can't mix insert/update true and insert/update false on the same joincolumn set in this configuration.
Adding a "@MapsId" annotation to the front of that will get rid of the insert/update conflict, but then I get the error that FK_INT cannot be null, despite having been explicitly advised otherwise.
PK_STRING must never be null, since it's part of the object's primary key.
FK_INT must be nullable, because the parent object of this relationship is optional, and therefore the returned property for the parent object can be null.
Since I can't get in touch with the people on the inside of Hibernate, does anybody here have any ideas?
Customer surveys are for companies who didn't pay proper attention to begin with.
Have you thought about creating an Embeddable Id? Whenever I have composite IDs I always put them in their own class and make it Embeddable.
The domain object
And code in another entity that references the EventVisit object.
Hope this is like what you are looking for. Whenever you have a composite id and referencing that object, it becomes very interesting, Embeddable Ids are definitely the way to go with this and makes for many things to work easier. I believe in your case you can put that insertable/updateable = "true" or "false directly in the Embeddable object.
I guess I forgot to mention it. The 2 entity types, as I mentioned, both inherit from the same base class, and yes, it has an EmbeddedID. What's killing me is that since the parent of the entity relationship has a composite key, a simple @JoinColumn doesn't help - I need to join on BOTH columns. In fact, barring some quick inspiration, I'm going to end up with an indirection table just so I can have a simple (nullable) JoinColumn on the child side.
What kills me is that since the parent is optional, in actual SQL terms, the PK_STRING is never allowed to be null, since it's shared between the composite key of the child and the composite foreign key of the parent. But if there is no parent, the FK_INT will be null. The idea, therefore is to get such a construct to be rendered up as a null object reference. Which is made more difficult because Hibernate refuses to let FK_INT be null.
I have a brief, delirious moment of hope when I saw the @NotFound annotation, then I remembered that it's a hack for Hibernate for stuff coming the other way. Or not coming, to be more accurate.