public void createAllKeys() throws MappingException { createForeignKeys(); if ( !isInverse() ) { createPrimaryKey(); } }
private void storeMiddleEntityRelationInformation(String mappedBy) { // Only if this is a relation (when there is a referenced entity). if ( referencedEntityName != null ) { if ( propertyValue.isInverse() ) { referencingEntityConfiguration.addToManyMiddleNotOwningRelation( propertyName, mappedBy, referencedEntityName ); } else { referencingEntityConfiguration.addToManyMiddleRelation( propertyName, referencedEntityName ); } } }
void addCollection() { final Type type = propertyValue.getType(); final Value value = propertyValue.getElement(); final boolean oneToManyAttachedType = type instanceof BagType || type instanceof SetType || type instanceof MapType || type instanceof ListType; final boolean inverseOneToMany = (value instanceof OneToMany) && (propertyValue.isInverse()); final boolean owningManyToOneWithJoinTableBidirectional = (value instanceof ManyToOne) && (propertyAuditingData.getRelationMappedBy() != null); final boolean fakeOneToManyBidirectional = (value instanceof OneToMany) && (propertyAuditingData.getAuditMappedBy() != null); if ( oneToManyAttachedType && (inverseOneToMany || fakeOneToManyBidirectional || owningManyToOneWithJoinTableBidirectional) ) { // A one-to-many relation mapped using @ManyToOne and @OneToMany(mappedBy="...") addOneToManyAttached( fakeOneToManyBidirectional ); } else { // All other kinds of relations require a middle (join) table. addWithMiddleTable(); } }
private String getMiddleTableName(Collection value, String entityName) { // We check how Hibernate maps the collection. if ( value.getElement() instanceof OneToMany && !value.isInverse() ) { // This must be a @JoinColumn+@OneToMany mapping. Generating the table name, as Hibernate doesn't use a // middle table for mapping this relation. return StringTools.getLastComponent( entityName ) + "_" + StringTools.getLastComponent( MappingTools.getReferencedEntityName( value.getElement() ) ); } // Hibernate uses a middle table for mapping this relation, so we get it's name directly. return value.getCollectionTable().getName(); }
protected void createBackReferences() { if ( collectionBinding.isOneToMany() && !collectionBinding.isInverse() && !collectionBinding.getKey().isNullable() ) { // for non-inverse one-to-many, with a not-null fk, add a backref! String entityName = ( (OneToMany) collectionBinding.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappingDocument.getMetadataCollector().getEntityBinding( entityName ); Backref prop = new Backref(); prop.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "Backref" ); prop.setUpdateable( false ); prop.setSelectable( false ); prop.setCollectionRole( collectionBinding.getRole() ); prop.setEntityName( collectionBinding.getOwner().getEntityName() ); prop.setValue( collectionBinding.getKey() ); referenced.addProperty( prop ); log.debugf( "Added virtual backref property [%s] : %s", prop.getName(), pluralAttributeSource.getAttributeRole().getFullPath() ); } }
if ( !collection.isInverse() && !collection.getKey().isNullable() ) {
isExtraLazy = collectionBinding.isExtraLazy(); isInverse = collectionBinding.isInverse();
bindFilters( false ); bindCollectionSecondPass( collection, null, fkJoinColumns, cascadeDeleteEnabled, property, mappings ); if ( !collection.isInverse() && !collection.getKey().isNullable() ) {
public CustomBasicCollectionPersister(Collection collection, CollectionRegionAccessStrategy cacheAccessStrategy, Configuration cfg, SessionFactoryImplementor factory) throws MappingException, CacheException { super(collection, cacheAccessStrategy, cfg, factory); String referencedPropertyName = collection.getReferencedPropertyName(); if (referencedPropertyName == null && collection.isInverse()) { referencedPropertyName = findMappedByProperty(collection); } this.mappedByProperty = referencedPropertyName; }
public CustomOneToManyPersister(Collection collection, CollectionRegionAccessStrategy cacheAccessStrategy, Configuration cfg, SessionFactoryImplementor factory) throws MappingException, CacheException { super(collection, cacheAccessStrategy, cfg, factory); String referencedPropertyName = collection.getReferencedPropertyName(); if (referencedPropertyName == null && collection.isInverse()) { referencedPropertyName = findMappedByProperty(collection); } this.mappedByProperty = referencedPropertyName; }
public void createAllKeys() throws MappingException { createForeignKeys(); if ( !isInverse() ) { createPrimaryKey(); } }
public void createAllKeys() throws MappingException { createForeignKeys(); if ( !isInverse() ) createPrimaryKey(); }
public void createAllKeys() throws MappingException { createForeignKeys(); if ( !isInverse() ) createPrimaryKey(); }
public void createAllKeys() throws MappingException { createForeignKeys(); if ( !isInverse() ) createPrimaryKey(); }
public void createAllKeys() throws MappingException { createForeignKeys(); if ( !isInverse() ) createPrimaryKey(); }
private void storeMiddleEntityRelationInformation(String mappedBy) { // Only if this is a relation (when there is a referenced entity). if ( referencedEntityName != null ) { if ( propertyValue.isInverse() ) { referencingEntityConfiguration.addToManyMiddleNotOwningRelation( propertyName, mappedBy, referencedEntityName ); } else { referencingEntityConfiguration.addToManyMiddleRelation( propertyName, referencedEntityName ); } } }
void addCollection() { final Value value = propertyValue.getElement(); final boolean oneToManyAttachedType = propertyValue instanceof Collection; final boolean inverseOneToMany = ( value instanceof OneToMany ) && propertyValue.isInverse(); final boolean owningManyToOneWithJoinTableBidirectional = ( value instanceof ManyToOne ) && propertyAuditingData.getRelationMappedBy() != null; final boolean fakeOneToManyBidirectional = (value instanceof OneToMany) && propertyAuditingData.getAuditMappedBy() != null; if ( oneToManyAttachedType && ( inverseOneToMany || fakeOneToManyBidirectional || owningManyToOneWithJoinTableBidirectional ) ) { // A one-to-many relation mapped using @ManyToOne and @OneToMany(mappedBy="...") addOneToManyAttached( fakeOneToManyBidirectional ); } else { // All other kinds of relations require a middle (join) table. addWithMiddleTable(); } }
private String getMiddleTableName(Collection value, String entityName) { // We check how Hibernate maps the collection. if ( value.getElement() instanceof OneToMany && !value.isInverse() ) { // This must be a @JoinColumn+@OneToMany mapping. Generating the table name, as Hibernate doesn't use a // middle table for mapping this relation. return StringTools.getLastComponent( entityName ) + "_" + StringTools.getLastComponent( MappingTools.getReferencedEntityName( value.getElement() ) ); } // Hibernate uses a middle table for mapping this relation, so we get it's name directly. return value.getMappedTable().getName(); }
protected void createBackReferences() { if ( collectionBinding.isOneToMany() && !collectionBinding.isInverse() && !collectionBinding.getKey().isNullable() ) { // for non-inverse one-to-many, with a not-null fk, add a backref! String entityName = ( (OneToMany) collectionBinding.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappingDocument.getMetadataCollector().getEntityBinding( entityName ); Backref prop = new Backref( metadataBuildingContext ); prop.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "Backref" ); prop.setUpdateable( false ); prop.setSelectable( false ); prop.setCollectionRole( collectionBinding.getRole() ); prop.setEntityName( collectionBinding.getOwner().getEntityName() ); prop.setValue( collectionBinding.getKey() ); referenced.addProperty( prop ); log.debugf( "Added virtual backref property [%s] : %s", prop.getName(), pluralAttributeSource.getAttributeRole().getFullPath() ); } }