Skip to content

Commit

Permalink
HHH-4417 - Add annotation support for UserCollectionType
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Mar 2, 2012
1 parent 0732db1 commit d7d9f0d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Expand Up @@ -125,6 +125,7 @@
import org.hibernate.annotations.Source;
import org.hibernate.annotations.Tuplizer;
import org.hibernate.annotations.Tuplizers;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.annotations.Where;
Expand Down
Expand Up @@ -29,6 +29,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
Expand Down Expand Up @@ -64,13 +65,15 @@
import org.hibernate.annotations.ManyToAny;
import org.hibernate.annotations.OptimisticLock;
import org.hibernate.annotations.OrderBy;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Persister;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.SQLInsert;
import org.hibernate.annotations.SQLUpdate;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.Where;
import org.hibernate.annotations.WhereJoinTable;
import org.hibernate.annotations.common.AssertionFailure;
Expand Down Expand Up @@ -111,6 +114,7 @@
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.TypeDef;

/**
* Base class for binding different types of collections to Hibernate configuration objects.
Expand Down Expand Up @@ -161,6 +165,9 @@ public abstract class CollectionBinder {
private AccessType accessType;
private boolean hibernateExtensionMapping;

private String explicitType = "";
private Properties explicitTypeParameters = new Properties();

protected Mappings getMappings() {
return mappings;
}
Expand Down Expand Up @@ -324,6 +331,15 @@ else if ( property.isAnnotationPresent( CollectionId.class ) ) {
);
}
result.setIsHibernateExtensionMapping( isHibernateExtensionMapping );

final Type typeAnnotation = property.getAnnotation( Type.class );
if ( typeAnnotation != null ) {
result.explicitType = typeAnnotation.type();
for ( Parameter param : typeAnnotation.parameters() ) {
result.explicitTypeParameters.setProperty( param.name(), param.value() );
}
}

return result;
}

Expand Down Expand Up @@ -386,6 +402,19 @@ public void bind() {
);
}

// set explicit type information
if ( explicitType != null ) {
final TypeDef typeDef = mappings.getTypeDef( explicitType );
if ( typeDef == null ) {
collection.setTypeName( explicitType );
collection.setTypeParameters( explicitTypeParameters );
}
else {
collection.setTypeName( typeDef.getTypeClass() );
collection.setTypeParameters( typeDef.getParameters() );
}
}

//set laziness
defineFetchingStrategy();
collection.setBatchSize( batchSize );
Expand Down

0 comments on commit d7d9f0d

Please sign in to comment.