collType + "." + this.mappedBy + " in " + collection.getOwnerEntityName() + "." + property.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() ); } }
property, keyXClass, this.collection.getOwnerEntityName(), holder.mapKeyAttributeConverterDescriptor( property, keyXClass ) );
ManyToAny anyAnn = property.getAnnotation( ManyToAny.class ); if ( LOG.isDebugEnabled() ) { String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); if ( isCollectionOfEntities && unique ) { LOG.debugf("Binding a OneToMany: %s through an association table", path); String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "Use of @OneToMany or @ManyToMany targeting an unmapped class: " + path + "[" + collType + "]" String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "@JoinTable is mandatory when @ManyToAny is used: " + path JoinTable joinTableAnn = parentPropertyHolder.getJoinTable( property ); if ( joinTableAnn != null && joinTableAnn.inverseJoinColumns().length > 0 ) { String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "Use of @JoinTable.inverseJoinColumns targeting an unmapped class: " + path + "[" + collType + "]" throw new AnnotationException( "Collection of elements must not have mappedBy or association reference an unmapped entity: " + collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName() "mappedBy reference an unknown target entity property: " + collType + "." + joinColumns[0].getMappedBy() + " in " + collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName()
collectionType = collectionBinding.getCollectionType(); navigableRole = new NavigableRole( collectionBinding.getRole() ); entityName = collectionBinding.getOwnerEntityName(); ownerPersister = factory.getEntityPersister( entityName ); queryLoaderName = collectionBinding.getLoaderName();
if ( propRef != null ) { collValue.setReferencedPropertyName( propRef ); buildingContext.getMetadataCollector().addPropertyReference( collValue.getOwnerEntityName(), propRef ); Ejb3Column.checkPropertyConsistency( joinColumns, collValue.getOwnerEntityName() ); key.setNullable( joinColumns.length == 0 || joinColumns[0].isNullable() ); key.setUpdateable( joinColumns.length == 0 || joinColumns[0].isUpdatable() );
.append( collType ).append( "." ).append( this.mappedBy ) .append( " in " ) .append( collection.getOwnerEntityName() ) .append( "." ) .append( property.getName() );
ManyToAny anyAnn = property.getAnnotation( ManyToAny.class ); if ( log.isDebugEnabled() ) { String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); if ( isCollectionOfEntities && unique ) { log.debug( "Binding a OneToMany: {} through an association table", path ); String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "Use of @OneToMany or @ManyToMany targeting an unmapped class: " + path + "[" + collType + "]" String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "@JoinTable is mandatory when @ManyToAny is used: " + path JoinTable joinTableAnn = parentPropertyHolder.getJoinTable( property ); if ( joinTableAnn != null && joinTableAnn.inverseJoinColumns().length > 0 ) { String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "Use of @JoinTable.inverseJoinColumns targeting an unmapped class: " + path + "[" + collType + "]" .append( collValue.getOwnerEntityName() ) .append( "." ) .append( joinColumns[0].getPropertyName() ); .append( collType ).append( "." ).append( joinColumns[0].getMappedBy() ) .append( " in " ) .append( collValue.getOwnerEntityName() ) .append( "." ) .append( joinColumns[0].getPropertyName() );
/** * <ul> * <li>Provide override collections with same rolename. * <li>Delay register collection,register by addClass method * </ul> */ @Override public void addCollection(Collection collection) throws DuplicateMappingException { String entityName = collection.getOwnerEntityName(); List<Collection> cols = tmpColls.get(entityName); if (null == cols) { cols = CollectUtils.newArrayList(); tmpColls.put(entityName, cols); } cols.add(collection); } }
if ( propRef != null ) { collValue.setReferencedPropertyName( propRef ); mappings.addPropertyReference( collValue.getOwnerEntityName(), propRef ); Ejb3Column.checkPropertyConsistency( joinColumns, collValue.getOwnerEntityName() ); key.setNullable( joinColumns.length == 0 || joinColumns[0].isNullable() ); key.setUpdateable( joinColumns.length == 0 || joinColumns[0].isUpdatable() );
@SuppressWarnings("unchecked") private String findMappedByProperty(Collection collection) { String ownerEntityName = collection.getOwnerEntityName(); Iterator<Column> columnIterator = collection.getKey().getColumnIterator(); List<String> columnNames = new ArrayList<>(); while (columnIterator.hasNext()) { Column column = columnIterator.next(); columnNames.add(column.getName()); } OneToMany oneToMany = (OneToMany) collection.getElement(); return findMappedByProperty(collection, ownerEntityName, columnNames, oneToMany.getAssociatedClass().getPropertyIterator()); }
mappings.addPropertyReference( coll.getOwnerEntityName(), propertyRef );
@SuppressWarnings("unchecked") private String findMappedByProperty(Collection collection) { String ownerEntityName = collection.getOwnerEntityName(); Iterator<Column> columnIterator = collection.getKey().getColumnIterator(); List<String> columnNames = new ArrayList<>(); while (columnIterator.hasNext()) { Column column = columnIterator.next(); columnNames.add(column.getName()); } OneToMany oneToMany = (OneToMany) collection.getElement(); Iterator propertyIterator = oneToMany.getAssociatedClass().getPropertyIterator(); while (propertyIterator.hasNext()) { Property property = (Property) propertyIterator.next(); if (property.getValue() instanceof ToOne) { ToOne toOne = (ToOne) property.getValue(); if (ownerEntityName.equals(toOne.getReferencedEntityName()) && matches(columnNames, collection.getKey().getColumnIterator())) { return property.getName(); } } } return null; }
mappings.addPropertyReference( coll.getOwnerEntityName(), propertyRef );
mappings.addPropertyReference( coll.getOwnerEntityName(), propertyRef );
private static Property createProperty(final Value value, final String propertyName, final String className, final Element subnode, final Mappings mappings, java.util.Map inheritedMetas) throws MappingException { value.setTypeUsingReflection( className, propertyName ); // this is done here 'cos we might only know the type here (ugly!) // TODO: improve this a lot: if ( value instanceof ToOne ) { ToOne toOne = (ToOne) value; String propertyRef = toOne.getReferencedPropertyName(); if ( propertyRef != null ) { mappings.addUniquePropertyReference( toOne.getReferencedEntityName(), propertyRef ); } } else if ( value instanceof Collection ) { Collection coll = (Collection) value; String propertyRef = coll.getReferencedPropertyName(); // not necessarily a *unique* property reference if ( propertyRef != null ) { mappings.addPropertyReference( coll.getOwnerEntityName(), propertyRef ); } } value.createForeignKey(); Property prop = new Property(); prop.setValue( value ); bindProperty( subnode, prop, mappings, inheritedMetas ); return prop; }
if ( propRef != null ) { collValue.setReferencedPropertyName( propRef ); mappings.addPropertyReference( collValue.getOwnerEntityName(), propRef ); Ejb3Column.checkPropertyConsistency( joinColumns, collValue.getOwnerEntityName() ); key.setNullable( joinColumns.length == 0 || joinColumns[0].isNullable() ); key.setUpdateable( joinColumns.length == 0 || joinColumns[0].isUpdatable() );
if ( propRef != null ) { collValue.setReferencedPropertyName( propRef ); mappings.addPropertyReference( collValue.getOwnerEntityName(), propRef ); Ejb3Column.checkPropertyConsistency( joinColumns, collValue.getOwnerEntityName() ); key.setNullable( joinColumns.length == 0 || joinColumns[0].isNullable() ); key.setUpdateable( joinColumns.length == 0 || joinColumns[0].isUpdatable() );
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() ); } }
.getMetadataBuildingContext() .getMetadataCollector() .getEntityBinding( getCollectionBinding().getOwnerEntityName() ); final Property referencedProperty = ownerDescriptor.getProperty( keySource.getReferencedPropertyName() ); targetColumns = referencedProperty.getValueMapping().getMappedColumns();