public class SharedJoinTableUniqueKeyBinder extends java.lang.Object
Gives every collection with a join table a uniqueness constraint of its own over its key column and the element, so that a join table several collections of one owner share stays unique per collection.
Two unidirectional hasMany to the same class without a joinTable mapping share one join table,
with a key column for each of them and one element column. Hibernate creates the table's implicit unique key when
it creates the keys of the first collection, over that collection's key column and the element column, and creates
none for the others, as the table has a unique key already (Set.createPrimaryKey). This binder runs after
the keys of each collection are created and completes what is missing, in the shape the database needs
(SharedJoinTableUniqueness). A collection whose table is its own already has its constraint and is left as
Hibernate bound it, and so is a collection without a join table, whose key the other side owns, or whose element is
a large object, which cannot be indexed and which Hibernate leaves without a key too. It also restricts a
collection that shares a key column with another on that table to its own rows, which Hibernate's removal of all
the rows of a collection by its key would otherwise not (collections with separate key columns delete only their
own rows by key and need no restriction).
Hibernate applies the restriction to the statements that load, count, join and delete the rows of a collection,
but loses it in the test of emptiness (is empty, is not empty); GORM translates that test as a size
test for a restricted many-to-many collection instead, through
RestrictedCollectionSqmTranslatorFactory (apache/grails-core#16748), except in
an update or delete of an entity whose hierarchy spans several tables.
A set cannot share a join table with a list or a map: the index column of a list or a map is not null, and the rows of the set leave it null, so saving the set fails on the first insert.
| Constructor and description |
|---|
SharedJoinTableUniqueKeyBinder(org.hibernate.boot.spi.MetadataBuildingContext metadataBuildingContext)Resolves the uniqueness for the dialect of the metadata being built. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
bind(org.hibernate.mapping.Collection collection)Gives a set the uniqueness constraint over its key columns and its element on its join table. |
|
public SharedJoinTableUniqueness |
getUniqueness()The uniqueness this binder applies. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
Resolves the uniqueness for the dialect of the metadata being built.
Gives a set the uniqueness constraint over its key columns and its element on its join table. A list or a map is keyed by its index, which its table has as part of the primary key, and a bag has no key at all; their elements repeat by design, so they are left as Hibernate bound them.
The uniqueness this binder applies.