[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3160?page=c...
]
Martin Garton commented on HHH-3160:
------------------------------------
I got around this in our case by making the child allow nulls for the index column and for
the parent foreign key. Together with setting the relationship as nullable=true on the
parent entity, this fixed the problem because the old children get removed from the parent
(columns set to null) before the new ones are inserted, so although the old chilren are
not deleted until after the new children are inserted, the constraint is never violated.
Having these columns as nullable is not perfect, but better IMO than not having the
constraint.
Support one-to-many list associations with constraints on both
(owner_id, position) and (child_id)
--------------------------------------------------------------------------------------------------
Key: HHH-3160
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3160
Project: Hibernate Core
Issue Type: Sub-task
Reporter: Gail Badner
Assignee: Gail Badner
Attachments: workaround.sql, workaround.sql
The logic used for removing entities from one-to-many list associations can cause
ConstraintViolationException will be thrown if there are constraints on both (owner_id,
position) and (child_id) in the "collection table". If the association is on a
join table, the "collection table" is the join table; otherwise, the
"collection table" is the child entity table..
Currently, SchemaExport does not put a constraint on (owner_id, position) when exporting
one-to-many list associations on a foreign key. SchemaExport should be updated to also
export this constraint.
See HHH-1268 for a description of how to reproduce this issue.
For one-to-many list associations on a foreign key, the workaround is to define the
unique constraint on (owner_id, position) in the child entity table as deferred. It is
assumed that the primary key in the child entity table is the child ID.
For a one-to-many list association on a join table, the workaround is to define the
constraint on (child_id) in the join table as deferred. It is assumed that the primary key
in the join table is (owner_id, position).
If your Dialect does not support deferred constraints, then the only workaround is to
exclude the unique constraint.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira