}
else {
XClass elementClass;
AnnotatedClassType classType;
CollectionPropertyHolder holder = null;
if ( BinderHelper.PRIMITIVE_NAMES.contains( collType.getName() ) ) {
classType = AnnotatedClassType.NONE;
elementClass = null;
holder = PropertyHolderBuilder.buildPropertyHolder(
collValue,
collValue.getRole(),
null,
property,
parentPropertyHolder,
mappings
);
}
else {
elementClass = collType;
classType = mappings.getClassType( elementClass );
holder = PropertyHolderBuilder.buildPropertyHolder(
collValue,
collValue.getRole(),
elementClass,
property,
parentPropertyHolder,
mappings
);
// 'parentPropertyHolder' is the PropertyHolder for the owner of the collection
// 'holder' is the CollectionPropertyHolder.
// 'property' is the collection XProperty
parentPropertyHolder.startingProperty( property );
//force in case of attribute override
boolean attributeOverride = property.isAnnotationPresent( AttributeOverride.class )
|| property.isAnnotationPresent( AttributeOverrides.class );
// todo : force in the case of Convert annotation(s) with embedded paths (beyond key/value prefixes)?
if ( isEmbedded || attributeOverride ) {
classType = AnnotatedClassType.EMBEDDABLE;
}
}
if ( AnnotatedClassType.EMBEDDABLE.equals( classType ) ) {
EntityBinder entityBinder = new EntityBinder();
PersistentClass owner = collValue.getOwner();
boolean isPropertyAnnotated;
//FIXME support @Access for collection of elements
//String accessType = access != null ? access.value() : null;
if ( owner.getIdentifierProperty() != null ) {
isPropertyAnnotated = owner.getIdentifierProperty().getPropertyAccessorName().equals( "property" );
}
else if ( owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0 ) {
Property prop = (Property) owner.getIdentifierMapper().getPropertyIterator().next();
isPropertyAnnotated = prop.getPropertyAccessorName().equals( "property" );
}
else {
throw new AssertionFailure( "Unable to guess collection property accessor name" );
}
PropertyData inferredData;
if ( isMap() ) {
//"value" is the JPA 2 prefix for map values (used to be "element")
if ( isHibernateExtensionMapping() ) {
inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass );
}
else {
inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "value", elementClass );
}
}
else {
if ( isHibernateExtensionMapping() ) {
inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "element", elementClass );
}
else {
//"collection&&element" is not a valid property name => placeholder
inferredData = new PropertyPreloadedData( AccessType.PROPERTY, "collection&&element", elementClass );
}
}
//TODO be smart with isNullable
boolean isNullable = true;
Component component = AnnotationBinder.fillComponent(
holder,
inferredData,
isPropertyAnnotated ? AccessType.PROPERTY : AccessType.FIELD,
isNullable,
entityBinder,
false,
false,
true,
mappings,
inheritanceStatePerClass
);
collValue.setElement( component );
if ( StringHelper.isNotEmpty( hqlOrderBy ) ) {
String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName();
String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );
if ( orderBy != null ) {
collValue.setOrderBy( orderBy );
}
}
}
else {
holder.prepare( property );
SimpleValueBinder elementBinder = new SimpleValueBinder();
elementBinder.setMappings( mappings );
elementBinder.setReturnedClassName( collType.getName() );
if ( elementColumns == null || elementColumns.length == 0 ) {
elementColumns = new Ejb3Column[1];
Ejb3Column column = new Ejb3Column();
column.setImplicit( false );
//not following the spec but more clean
column.setNullable( true );
column.setLength( Ejb3Column.DEFAULT_COLUMN_LENGTH );
column.setLogicalColumnName( Collection.DEFAULT_ELEMENT_COLUMN_NAME );
//TODO create an EMPTY_JOINS collection
column.setJoins( new HashMap<String, Join>() );
column.setMappings( mappings );
column.bind();
elementColumns[0] = column;
}
//override the table
for (Ejb3Column column : elementColumns) {
column.setTable( collValue.getCollectionTable() );
}
elementBinder.setColumns( elementColumns );
elementBinder.setType(
property,
elementClass,
collValue.getOwnerEntityName(),
holder.resolveElementAttributeConverterDefinition( elementClass )
);
elementBinder.setPersistentClassName( propertyHolder.getEntityName() );
elementBinder.setAccessType( accessType );
collValue.setElement( elementBinder.make() );
String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy );