Skip to content

Commit

Permalink
HHH-10069 - ClassCastException between CompositeCustomType and Compon…
Browse files Browse the repository at this point in the history
…entType part 2
  • Loading branch information
sebersole committed Sep 2, 2015
1 parent 8916346 commit 961b5e8
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 40 deletions.
Expand Up @@ -40,6 +40,7 @@
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.IntegerType;
import org.hibernate.type.LongType;
import org.hibernate.type.PostgresUUIDType;
Expand Down Expand Up @@ -686,8 +687,8 @@ public boolean needsRecreate(CollectionPersister persister) {
// the param would have to be bound twice. Until we eventually add "parameter bind points" concepts to the
// AST in ORM 5+, handling this type of condition is either extremely difficult or impossible. Forcing
// recreation isn't ideal, but not really any other option in ORM 4.
if (persister.getElementType() instanceof ComponentType) {
ComponentType componentType = (ComponentType) persister.getElementType();
if ( persister.getElementType() instanceof CompositeType ) {
CompositeType componentType = (CompositeType) persister.getElementType();
return !componentType.hasNotNullProperty();
}
return false;
Expand Down
Expand Up @@ -78,6 +78,7 @@
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.DbTimestampType;
import org.hibernate.type.Type;
import org.hibernate.type.VersionType;
Expand Down Expand Up @@ -389,7 +390,7 @@ protected void createFromJoinElement(
null,
false
);
fromElement = factory.createComponentJoin( (ComponentType) dot.getDataType() );
fromElement = factory.createComponentJoin( (CompositeType) dot.getDataType() );
}
else {
fromElement = dot.getImpliedJoin();
Expand Down
Expand Up @@ -11,7 +11,7 @@
import org.hibernate.internal.util.StringHelper;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.PropertyMapping;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;

/**
Expand All @@ -21,7 +21,7 @@
*/
public class ComponentJoin extends FromElement {
private final String componentPath;
private final ComponentType componentType;
private final CompositeType componentType;

private final String componentProperty;
private final String[] columns;
Expand All @@ -32,7 +32,7 @@ public ComponentJoin(
FromElement origin,
String alias,
String componentPath,
ComponentType componentType) {
CompositeType componentType) {
super( fromClause, origin, alias );
this.componentPath = componentPath;
this.componentType = componentType;
Expand Down Expand Up @@ -60,7 +60,7 @@ public String getComponentProperty() {
return componentProperty;
}

public ComponentType getComponentType() {
public CompositeType getComponentType() {
return componentType;
}

Expand Down
Expand Up @@ -22,7 +22,7 @@
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;

Expand Down Expand Up @@ -286,7 +286,7 @@ public FromElement createEntityJoin(
return elem;
}

public FromElement createComponentJoin(ComponentType type) {
public FromElement createComponentJoin(CompositeType type) {

// need to create a "place holder" from-element that can store the component/alias for this
// component join
Expand Down
Expand Up @@ -15,7 +15,7 @@
import org.hibernate.QueryException;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;

import antlr.collections.AST;
Expand Down Expand Up @@ -157,9 +157,9 @@ private void visitPropertySpecNodes(AST propertyNode, List types) {
}

if ( !explicitIdInsertion ) {
if ( persister.getIdentifierType() instanceof ComponentType ) {
if ( persister.getIdentifierType() instanceof CompositeType ) {
if ( componentIds == null ) {
String[] propertyNames = ( (ComponentType) persister.getIdentifierType() ).getPropertyNames();
String[] propertyNames = ( (CompositeType) persister.getIdentifierType() ).getPropertyNames();
componentIds = new HashSet();
for ( int i = 0; i < propertyNames.length; i++ ) {
componentIds.add( propertyNames[i] );
Expand Down
Expand Up @@ -12,7 +12,7 @@

import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.PropertyMapping;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;

/**
Expand All @@ -29,7 +29,7 @@ class ComponentCollectionCriteriaInfoProvider implements CriteriaInfoProvider {
throw new IllegalArgumentException( "persister for role " + persister.getRole() + " is not a collection-of-component" );
}

ComponentType componentType = (ComponentType) persister.getElementType();
CompositeType componentType = (CompositeType) persister.getElementType();
String[] names = componentType.getPropertyNames();
Type[] types = componentType.getSubtypes();

Expand Down
Expand Up @@ -34,7 +34,6 @@
import org.hibernate.persister.entity.Joinable;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;

Expand Down Expand Up @@ -247,7 +246,7 @@ private void addKeyManyToOnesToSession(ResultSetProcessingContextImpl context, C
( (Session) context.getSession() ).buildLockRequest( LockOptions.NONE ).lock( subValue );
}
else if ( subType.isComponentType() ) {
addKeyManyToOnesToSession( context, (ComponentType) subType, subValue );
addKeyManyToOnesToSession( context, (CompositeType) subType, subValue );
}
}
}
Expand Down
Expand Up @@ -37,7 +37,7 @@ public interface ProxyFactory {
* @param setIdentifierMethod Reference to the identifier setter method;
* invocation on this method should not force initialization
* @param componentIdType For composite identifier types, a reference to
* the {@link org.hibernate.type.ComponentType type} of the identifier
* the {@link org.hibernate.type.CompositeType type} of the identifier
* property; again accessing the id should generally not cause
* initialization - but need to bear in mind <key-many-to-one/>
* mappings.
Expand Down
24 changes: 19 additions & 5 deletions hibernate-core/src/main/java/org/hibernate/type/AnyType.java
Expand Up @@ -20,6 +20,7 @@
import org.hibernate.FetchMode;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.PropertyNotFoundException;
import org.hibernate.TransientObjectException;
import org.hibernate.engine.internal.ForeignKeys;
import org.hibernate.engine.jdbc.Size;
Expand All @@ -35,8 +36,6 @@
import org.hibernate.proxy.HibernateProxyHelper;
import org.hibernate.proxy.LazyInitializer;

import org.dom4j.Node;

/**
* Handles "any" mappings
*
Expand All @@ -49,9 +48,6 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT

/**
* Intended for use only from legacy {@link ObjectType} type definition
*
* @param discriminatorType
* @param identifierType
*/
protected AnyType(Type discriminatorType, Type identifierType) {
this( null, discriminatorType, identifierType );
Expand Down Expand Up @@ -375,6 +371,18 @@ public String[] getPropertyNames() {
return PROPERTY_NAMES;
}

@Override
public int getPropertyIndex(String name) {
if ( PROPERTY_NAMES[0].equals( name ) ) {
return 0;
}
else if ( PROPERTY_NAMES[1].equals( name ) ) {
return 1;
}

throw new PropertyNotFoundException( "Unable to locate property named " + name + " on AnyType" );
}

@Override
public Object getPropertyValue(Object component, int i, SessionImplementor session) throws HibernateException {
return i==0
Expand Down Expand Up @@ -415,6 +423,12 @@ public boolean[] getPropertyNullability() {
return NULLABILITY;
}

@Override
public boolean hasNotNullProperty() {
// both are non-nullable
return true;
}

@Override
public Type[] getSubtypes() {
return new Type[] {discriminatorType, identifierType };
Expand Down
Expand Up @@ -31,9 +31,6 @@
import org.hibernate.tuple.component.ComponentMetamodel;
import org.hibernate.tuple.component.ComponentTuplizer;

import org.dom4j.Element;
import org.dom4j.Node;

/**
* Handles "component" mappings
*
Expand Down Expand Up @@ -723,6 +720,7 @@ public boolean isEmbedded() {
return false;
}

@Override
public int getPropertyIndex(String name) {
String[] names = getPropertyNames();
for ( int i = 0, max = names.length; i < max; i++ ) {
Expand Down Expand Up @@ -817,6 +815,7 @@ public Object extract(CallableStatement statement, String[] paramNames, SessionI
return resolve( values, session, null );
}

@Override
public boolean hasNotNullProperty() {
return hasNotNullProperty;
}
Expand Down
Expand Up @@ -17,19 +17,17 @@
import org.hibernate.FetchMode;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.PropertyNotFoundException;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.engine.spi.CascadeStyles;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.engine.jdbc.Size;
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.usertype.LoggableUserType;

import org.dom4j.Element;
import org.dom4j.Node;

/**
* Adapts {@link CompositeUserType} to the {@link Type} interface
*
Expand Down Expand Up @@ -73,6 +71,19 @@ public String[] getPropertyNames() {
return userType.getPropertyNames();
}

@Override
public int getPropertyIndex(String name) {
String[] names = getPropertyNames();
for ( int i = 0, max = names.length; i < max; i++ ) {
if ( names[i].equals( name ) ) {
return i;
}
}
throw new PropertyNotFoundException(
"Unable to locate property named " + name + " on " + getReturnedClass().getName()
);
}

public Object[] getPropertyValues(Object component, SessionImplementor session) throws HibernateException {
return getPropertyValues( component, EntityMode.POJO );
}
Expand Down Expand Up @@ -278,4 +289,10 @@ public boolean isDirty(Object old, Object current, boolean[] checkable, SessionI
public boolean isEmbedded() {
return false;
}

@Override
public boolean hasNotNullProperty() {
// We just don't know. So assume nullable
return false;
}
}

0 comments on commit 961b5e8

Please sign in to comment.