public static String getReferencedEntityName(Value value) { if ( value instanceof ToOne ) { return ( (ToOne) value ).getReferencedEntityName(); } else if ( value instanceof OneToMany ) { return ( (OneToMany) value ).getReferencedEntityName(); } else if ( value instanceof Collection ) { return getReferencedEntityName( ( (Collection) value ).getElement() ); } return null; }
private EntityType getEntityType() { return metadata.getTypeResolver().getTypeFactory().manyToOne( getReferencedEntityName(), true, null, false, false, isIgnoreNotFound(), false ); }
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 ); } }
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 ); } }
@Override protected void createBackReferences() { super.createBackReferences(); boolean indexIsFormula = false; Iterator itr = getCollectionBinding().getIndex().getColumnIterator(); while ( itr.hasNext() ) { if ( ( (Selectable) itr.next() ).isFormula() ) { indexIsFormula = true; } } if ( getCollectionBinding().isOneToMany() && !getCollectionBinding().getKey().isNullable() && !getCollectionBinding().isInverse() && !indexIsFormula ) { final String entityName = ( (OneToMany) getCollectionBinding().getElement() ).getReferencedEntityName(); final PersistentClass referenced = getMappingDocument().getMetadataCollector().getEntityBinding( entityName ); final IndexBackref ib = new IndexBackref(); ib.setName( '_' + getCollectionBinding().getOwnerEntityName() + "." + getPluralAttributeSource().getName() + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( getCollectionBinding().getRole() ); ib.setEntityName( getCollectionBinding().getOwner().getEntityName() ); ib.setValue( getCollectionBinding().getIndex() ); referenced.addProperty( ib ); } } }
oneToMany.setIgnoreNotFound( ignoreNotFound ); String assocClass = oneToMany.getReferencedEntityName(); PersistentClass associatedClass = (PersistentClass) persistentClasses.get( assocClass ); if ( jpaOrderBy != null ) { && !collection.getKey().isNullable() ) { String entityName = oneToMany.getReferencedEntityName(); PersistentClass referenced = buildingContext.getMetadataCollector().getEntityBinding( entityName ); Backref prop = new Backref();
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() ); } }
@Override public void doSecondPass(Map persistentClasses) throws org.hibernate.MappingException { bindCollectionTable(); bindCollectionKey(); bindCollectionIdentifier(); bindCollectionIndex(); bindCollectionElement(); createBackReferences(); collectionBinding.createAllKeys(); if ( debugEnabled ) { log.debugf( "Mapped collection : " + getPluralAttributeSource().getAttributeRole().getFullPath() ); log.debugf( " + table -> " + getCollectionBinding().getTable().getName() ); log.debugf( " + key -> " + columns( getCollectionBinding().getKey() ) ); if ( getCollectionBinding().isIndexed() ) { log.debugf( " + index -> " + columns( ( (IndexedCollection) getCollectionBinding() ).getIndex() ) ); } if ( getCollectionBinding().isOneToMany() ) { log.debugf( " + one-to-many -> " + ( (OneToMany) getCollectionBinding().getElement() ).getReferencedEntityName() ); } else { log.debugf( " + element -> " + columns( getCollectionBinding().getElement() ) ); } } }
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();
private String getReferencedEntityName(Value element) { if ( element instanceof OneToMany ) { return ( (OneToMany) element ).getReferencedEntityName(); } else if ( element instanceof ToOne ) { return ( (ToOne) element ).getReferencedEntityName(); } else { return null; } }
oneToMany.setIgnoreNotFound( ignoreNotFound ); String assocClass = oneToMany.getReferencedEntityName(); PersistentClass associatedClass = (PersistentClass) persistentClasses.get( assocClass ); String orderBy = buildOrderByClauseFromHql( hqlOrderBy, associatedClass, collection.getRole() ); && !collection.getKey().isNullable() ) { String entityName = oneToMany.getReferencedEntityName(); PersistentClass referenced = mappings.getClass( entityName ); Backref prop = new Backref();
private EntityType getEntityType() { return TypeFactory.manyToOne( getReferencedEntityName(), null, false, isEmbedded(), isIgnoreNotFound() ); }
private EntityType getEntityType() { return TypeFactory.manyToOne( getReferencedEntityName(), null, false, false, isEmbedded(), isIgnoreNotFound() ); }
public static String getReferencedEntityName(Value value) { if ( value instanceof ToOne ) { return ( (ToOne) value ).getReferencedEntityName(); } else if ( value instanceof OneToMany ) { return ( (OneToMany) value ).getReferencedEntityName(); } else if ( value instanceof Collection ) { return getReferencedEntityName( ( (Collection) value ).getElement() ); } return null; }
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 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 } }
list.setBaseIndex( indexColumn.getBase() ); if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) { String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappings.getClass( entityName ); IndexBackref ib = new IndexBackref();
private EntityType getEntityType() { return mappings.getTypeResolver().getTypeFactory().manyToOne( getReferencedEntityName(), null, false, false, isEmbedded(), isIgnoreNotFound(), false ); }
private EntityType getEntityType() { return mappings.getTypeResolver().getTypeFactory().manyToOne( getReferencedEntityName(), null, false, false, isEmbedded(), isIgnoreNotFound(), false ); }
@Test public void testCreateOneToMany() { PersistentClass orders = metadata.getEntityBinding(PACKAGE_NAME + ".Orders"); Property itemset = orders.getProperty("itemsForRelatedOrderId"); Collection col = (Collection) itemset.getValue(); OneToMany otm = (OneToMany) col.getElement(); Assert.assertEquals(otm.getReferencedEntityName(), PACKAGE_NAME + ".Item"); Assert.assertEquals(otm.getAssociatedClass().getClassName(), PACKAGE_NAME + ".Item"); Assert.assertEquals(otm.getTable().getName(), "ORDERS"); Assert.assertNotNull(itemset); Assert.assertTrue(itemset.getValue() instanceof Set); }