Refine search
); org.hibernate.mapping.OneToMany oneToMany = new org.hibernate.mapping.OneToMany( buildingContext, collection.getOwner() ); collection.setElement( oneToMany ); oneToMany.setReferencedEntityName( collectionType.getName() ); oneToMany.setIgnoreNotFound( ignoreNotFound ); String assocClass = oneToMany.getReferencedEntityName(); PersistentClass associatedClass = (PersistentClass) persistentClasses.get( assocClass ); if ( jpaOrderBy != null ) { jpaOrderBy.value(), associatedClass, collection.getRole() ); if ( StringHelper.isNotEmpty( orderByFragment ) ) { ); oneToMany.setAssociatedClass( associatedClass ); for (Ejb3JoinColumn column : fkJoinColumns) { column.setPersistentClass( associatedClass, joins, inheritanceStatePerClass ); && !collection.getKey().isNullable() ) { String entityName = oneToMany.getReferencedEntityName(); PersistentClass referenced = buildingContext.getMetadataCollector().getEntityBinding( entityName ); Backref prop = new Backref();
private PersistentClass getReferenceCollectionClass(Collection collectionValue) { PersistentClass referencedClass = null; if ( collectionValue.getElement() instanceof OneToMany ) { final OneToMany oneToManyValue = (OneToMany) collectionValue.getElement(); referencedClass = oneToManyValue.getAssociatedClass(); } else if ( collectionValue.getElement() instanceof ManyToOne ) { // Case for bi-directional relation with @JoinTable on the owning @ManyToOne side. final ManyToOne manyToOneValue = (ManyToOne) collectionValue.getElement(); referencedClass = manyToOneValue.getMetadata().getEntityBinding( manyToOneValue.getReferencedEntityName() ); } return referencedClass; }
private EntityType getEntityType() { return metadata.getTypeResolver().getTypeFactory().manyToOne( getReferencedEntityName(), true, null, false, false, isIgnoreNotFound(), false ); }
final SimpleValue elementBinding = new SimpleValue( getMappingDocument(), getCollectionBinding().getCollectionTable() ); getCollectionBinding().setElement( elementBinding ); getCollectionBinding().setWhere( getPluralAttributeSource().getWhere() ); final PluralAttributeElementSourceOneToMany elementSource = (PluralAttributeElementSourceOneToMany) getPluralAttributeSource().getElementSource(); final OneToMany elementBinding = new OneToMany( getMappingDocument(), getCollectionBinding().getOwner() collectionBinding.setWhere( StringHelper.getNonEmptyOrConjunctionIfBothNonEmpty( referencedEntityBinding.getWhere(), getPluralAttributeSource().getWhere() elementBinding.setReferencedEntityName( referencedEntityBinding.getEntityName() ); elementBinding.setAssociatedClass( referencedEntityBinding ); elementBinding.setIgnoreNotFound( elementSource.isIgnoreNotFound() ); getCollectionBinding().setManyToManyWhere( StringHelper.getNonEmptyOrConjunctionIfBothNonEmpty( referencedEntityBinding.getWhere(), elementSource.getWhere()
throws MappingException { if ( collection.isOneToMany() ) { OneToMany oneToMany = (OneToMany) collection.getElement(); String assocClass = oneToMany.getReferencedEntityName(); PersistentClass persistentClass = (PersistentClass) persistentClasses.get( assocClass ); if ( persistentClass == null ) { throw new MappingException( "Association references unmapped class: " + assocClass ); oneToMany.setAssociatedClass( persistentClass ); collection.setCollectionTable( persistentClass.getTable() ); String propRef = collection.getReferencedPropertyName(); if ( propRef == null ) { keyVal = collection.getOwner().getIdentifier(); keyVal = (KeyValue) collection.getOwner().getProperty( propRef ).getValue(); SimpleValue key = new DependantValue( collection.getCollectionTable(), keyVal ); && !collection.getKey().isNullable() ) { String entityName = ( (OneToMany) collection.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappings.getClass( entityName ); Backref prop = new Backref();
collection.setRole(path); collection.setInverse( "true".equals( inverseNode.getValue() ) ); collection.setMutable( !"false".equals( mutableNode.getValue() ) ); collection.setSubselectLoadable(true); collection.getOwner().setSubselectLoadableCollections(true); OneToMany oneToMany = new OneToMany( mappings, collection.getOwner() ); collection.setElement( oneToMany ); bindOneToMany( oneToManyNode, oneToMany, mappings ); Table ownerTable = collection.getOwner().getTable(); collection.getOwner().getEntityName(), logicalOwnerTableName , null,
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { final boolean debugEnabled = LOG.isDebugEnabled(); if ( debugEnabled ) { LOG.debugf( "Second pass for collection: %s", collection.getRole() ); } secondPass( persistentClasses, localInheritedMetas ); // using local since the inheritedMetas at this point is not the correct map since it is always the empty map collection.createAllKeys(); if ( debugEnabled ) { String msg = "Mapped collection key: " + columns( collection.getKey() ); if ( collection.isIndexed() ) msg += ", index: " + columns( ( (IndexedCollection) collection ).getIndex() ); if ( collection.isOneToMany() ) { msg += ", one-to-many: " + ( (OneToMany) collection.getElement() ).getReferencedEntityName(); } else { msg += ", element: " + columns( collection.getElement() ); } LOG.debug( msg ); } }
+ collection.getRole() + " -> " + collection.getCollectionTable().getName()); collection.setOrderBy(buildOrderByClause(propertyToSortBy.getName(), associatedClass, collection.getRole(), propConfig.getOrder() != null ? propConfig.getOrder() : "asc")); OneToMany oneToMany = (OneToMany) collection.getElement(); String associatedClassName = oneToMany.getReferencedEntityName(); throw new MappingException("Association references unmapped class: " + oneToMany.getReferencedEntityName()); oneToMany.setAssociatedClass(associatedClass); if (shouldBindCollectionWithForeignKey(property)) { collection.setCollectionTable(associatedClass.getTable());
collection.setCollectionTable(collectionTable); // CHILD+ ManyToOne element = new ManyToOne(mdbc, collection.getCollectionTable() ); collection.setElement( element ); OneToMany oneToMany = new OneToMany(mdbc, collection.getOwner() ); oneToMany.setReferencedEntityName( tableToClassName ); // Child metadataCollector.addSecondPass( new JdbcCollectionSecondPass(mdbc, collection) ); String propRef = collection.getReferencedPropertyName(); if (propRef==null) { referencedKeyValue = collection.getOwner().getIdentifier(); referencedKeyValue = (KeyValue) collection.getOwner() .getProperty(propRef) .getValue(); return makeCollectionProperty(StringHelper.unqualify( collection.getRole() ), true, rc.getTable(), foreignKey, collection, true);
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() ); } }
collection.setRole( StringHelper.qualify( className, path ) ); collection.setInverse( "true".equals( inverseNode.getValue() ) ); collection.setOptimisticLocked( olNode == null || "true".equals( olNode.getValue() ) ); collection.setSubselectLoadable(true); collection.getOwner().setSubselectLoadableCollections(true); OneToMany oneToMany = new OneToMany( collection.getOwner() ); collection.setElement( oneToMany ); bindOneToMany( oneToManyNode, oneToMany, mappings );
collection.setRole(StringHelper.qualify(property.getDomainClass().getFullName(), propertyName)); collection.setFetchMode(FetchMode.JOIN); collection.setFetchMode(pc.getFetch()); OneToMany oneToMany = new OneToMany(mappings, collection.getOwner()); collection.setElement(oneToMany); bindOneToMany(property, oneToMany, mappings); } else { bindCollectionTable(property, mappings, collection, owner.getTable(), sessionFactoryBeanName);
PropertyHolder valueHolder = PropertyHolderBuilder.buildPropertyHolder( this.collection, StringHelper.qualify( this.collection.getRole(), "key" ), null, null, list.setBaseIndex( indexColumn.getBase() ); if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) { String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName(); PersistentClass referenced = buildingContext.getMetadataCollector().getEntityBinding( entityName ); IndexBackref ib = new IndexBackref(); ib.setSelectable( false ); ib.setCollectionRole( list.getRole() ); ib.setEntityName( list.getOwner().getEntityName() ); ib.setValue( list.getIndex() ); referenced.addProperty( ib ); throw new AnnotationException( "List/array has to be annotated with an @OrderColumn (or @IndexColumn): " + coll.getRole() );
private void bindCollectionSecondPass( Collection collection, Map<?,?> persistentClasses, MetadataBuildingContext mdbc, Map<?,?> inheritedMetas) throws MappingException { if(collection.isOneToMany() ) { OneToMany oneToMany = (OneToMany) collection.getElement(); PersistentClass persistentClass = mdbc.getMetadataCollector().getEntityBinding(oneToMany.getReferencedEntityName()); if (persistentClass==null) throw new MappingException( "Association " + collection.getRole() + " references unmapped class: " + oneToMany.getReferencedEntityName() ); oneToMany.setAssociatedClass(persistentClass); // Child } }
private void createIndexBackRef( MappingDocument mappingDocument, IndexedPluralAttributeSource pluralAttributeSource, IndexedCollection collectionBinding) { if ( collectionBinding.isOneToMany() && !collectionBinding.getKey().isNullable() && !collectionBinding.isInverse() ) { final String entityName = ( (OneToMany) collectionBinding.getElement() ).getReferencedEntityName(); final PersistentClass referenced = mappingDocument.getMetadataCollector().getEntityBinding( entityName ); final IndexBackref ib = new IndexBackref(); ib.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( collectionBinding.getRole() ); ib.setEntityName( collectionBinding.getOwner().getEntityName() ); ib.setValue( collectionBinding.getIndex() ); referenced.addProperty( ib ); } }
/** * Binds a unidirectional one-to-many creating a psuedo back reference property in the process. * * @param property * @param mappings * @param collection */ protected void bindUnidirectionalOneToMany(org.grails.datastore.mapping.model.types.OneToMany property, Mappings mappings, Collection collection) { Value v = collection.getElement(); v.createForeignKey(); String entityName; if (v instanceof ManyToOne) { ManyToOne manyToOne = (ManyToOne) v; entityName = manyToOne.getReferencedEntityName(); } else { entityName = ((OneToMany) v).getReferencedEntityName(); } collection.setInverse(false); PersistentClass referenced = mappings.getClass(entityName); Backref prop = new Backref(); PersistentEntity owner = property.getOwner(); prop.setEntityName(owner.getName()); prop.setName(UNDERSCORE + addUnderscore(owner.getJavaClass().getSimpleName(), property.getName()) + "Backref"); prop.setUpdateable(false); prop.setInsertable(true); prop.setCollectionRole(collection.getRole()); prop.setValue(collection.getKey()); prop.setOptional(true); referenced.addProperty(prop); }
entityName = manyToOne.getReferencedEntityName(); } else { entityName = ((OneToMany) element).getReferencedEntityName(); Class<?> mappedClass = referenced.getMappedClass(); Mapping m = getMapping(mappedClass); prop.setOptional(false); referenced.addProperty(prop); ib.setEntityName(list.getOwner().getEntityName()); ib.setValue(list.getIndex()); referenced.addProperty(ib);
set.setCollectionTable(clazzMany.getTable()); OneToMany oneToMany = new OneToMany(mappings, set.getOwner()); set.setElement(oneToMany); oneToMany.setReferencedEntityName(manyMDQualifiedTableName); oneToMany.setAssociatedClass(clazzMany); Table tableMany = clazzMany.getTable(); Table tableOne = clazzOne.getTable(); List<Column> oneColumns = new ArrayList<Column>(); List<Column> manyColumns = new ArrayList<Column>();
@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()); }
throw new MappingException( "Association references unmapped class: " + assocClass ); oneToMany.setAssociatedClass( persistentClass ); collection.setCollectionTable( persistentClass.getTable() ); " -> " + collection.getCollectionTable().getName() ); keyVal = (KeyValue) collection.getOwner().getProperty( propRef ).getValue(); SimpleValue key = new DependantValue( collection.getCollectionTable(), keyVal ); key.setCascadeDeleteEnabled( "cascade" .equals( subnode.attributeValue( "on-delete" ) ) ); SimpleValue elt = new SimpleValue( collection.getCollectionTable() ); collection.setElement( elt ); bindSimpleValue(