Java Code Examples for org.hibernate.mapping.List#isOneToMany()

The following examples show how to use org.hibernate.mapping.List#isOneToMany() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HbmBinder.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Called for Lists, arrays, primitive arrays
 */
public static void bindListSecondPass(Element node, List list, java.util.Map classes,
		Mappings mappings, java.util.Map inheritedMetas) throws MappingException {

	bindCollectionSecondPass( node, list, classes, mappings, inheritedMetas );

	Element subnode = node.element( "list-index" );
	if ( subnode == null ) subnode = node.element( "index" );
	SimpleValue iv = new SimpleValue( list.getCollectionTable() );
	bindSimpleValue(
			subnode,
			iv,
			list.isOneToMany(),
			IndexedCollection.DEFAULT_INDEX_COLUMN_NAME,
			mappings
		);
	iv.setTypeName( "integer" );
	list.setIndex( iv );
	String baseIndex = subnode.attributeValue( "base" );
	if ( baseIndex != null ) list.setBaseIndex( Integer.parseInt( baseIndex ) );
	list.setIndexNodeName( subnode.attributeValue("node") );

	if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) {
		String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName();
		PersistentClass referenced = mappings.getClass( entityName );
		IndexBackref ib = new IndexBackref();
		ib.setName( '_' + node.attributeValue( "name" ) + "IndexBackref" );
		ib.setUpdateable( false );
		ib.setSelectable( false );
		ib.setCollectionRole( list.getRole() );
		ib.setEntityName( list.getOwner().getEntityName() );
		ib.setValue( list.getIndex() );
		// ( (Column) ( (SimpleValue) ic.getIndex() ).getColumnIterator().next()
		// ).setNullable(false);
		referenced.addProperty( ib );
	}
}
 
Example 2
Source File: ListBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void bindIndex(final MetadataBuildingContext buildingContext) {
	if ( !indexColumn.isImplicit() ) {
		PropertyHolder valueHolder = PropertyHolderBuilder.buildPropertyHolder(
				this.collection,
				StringHelper.qualify( this.collection.getRole(), "key" ),
				null,
				null,
				propertyHolder,
				getBuildingContext()
		);
		List list = (List) this.collection;
		if ( !list.isOneToMany() ) indexColumn.forceNotNull();
		indexColumn.setPropertyHolder( valueHolder );
		SimpleValueBinder value = new SimpleValueBinder();
		value.setColumns( new Ejb3Column[] { indexColumn } );
		value.setExplicitType( "integer" );
		value.setBuildingContext( getBuildingContext() );
		SimpleValue indexValue = value.make();
		indexColumn.linkWithValue( indexValue );
		list.setIndex( indexValue );
		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.setName( '_' + propertyName + "IndexBackref" );
			ib.setUpdateable( false );
			ib.setSelectable( false );
			ib.setCollectionRole( list.getRole() );
			ib.setEntityName( list.getOwner().getEntityName() );
			ib.setValue( list.getIndex() );
			referenced.addProperty( ib );
		}
	}
	else {
		Collection coll = this.collection;
		throw new AnnotationException(
				"List/array has to be annotated with an @OrderColumn (or @IndexColumn): "
						+ coll.getRole()
		);
	}
}