Skip to content

Commit 74bfdd9

Browse files
committed
HHH-10069 - ClassCastException between CompositeCustomType and ComponentType part 2
(cherry picked from commit 961b5e8)
1 parent 791a3a5 commit 74bfdd9

File tree

12 files changed

+88
-40
lines changed

12 files changed

+88
-40
lines changed

hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.hibernate.persister.entity.EntityPersister;
4141
import org.hibernate.pretty.MessageHelper;
4242
import org.hibernate.type.ComponentType;
43+
import org.hibernate.type.CompositeType;
4344
import org.hibernate.type.IntegerType;
4445
import org.hibernate.type.LongType;
4546
import org.hibernate.type.PostgresUUIDType;
@@ -686,8 +687,8 @@ public boolean needsRecreate(CollectionPersister persister) {
686687
// the param would have to be bound twice. Until we eventually add "parameter bind points" concepts to the
687688
// AST in ORM 5+, handling this type of condition is either extremely difficult or impossible. Forcing
688689
// recreation isn't ideal, but not really any other option in ORM 4.
689-
if (persister.getElementType() instanceof ComponentType) {
690-
ComponentType componentType = (ComponentType) persister.getElementType();
690+
if ( persister.getElementType() instanceof CompositeType ) {
691+
CompositeType componentType = (CompositeType) persister.getElementType();
691692
return !componentType.hasNotNullProperty();
692693
}
693694
return false;

hibernate-core/src/main/java/org/hibernate/hql/internal/ast/HqlSqlWalker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import org.hibernate.sql.JoinType;
7979
import org.hibernate.type.AssociationType;
8080
import org.hibernate.type.ComponentType;
81+
import org.hibernate.type.CompositeType;
8182
import org.hibernate.type.DbTimestampType;
8283
import org.hibernate.type.Type;
8384
import org.hibernate.type.VersionType;
@@ -389,7 +390,7 @@ protected void createFromJoinElement(
389390
null,
390391
false
391392
);
392-
fromElement = factory.createComponentJoin( (ComponentType) dot.getDataType() );
393+
fromElement = factory.createComponentJoin( (CompositeType) dot.getDataType() );
393394
}
394395
else {
395396
fromElement = dot.getImpliedJoin();

hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/ComponentJoin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.hibernate.internal.util.StringHelper;
1212
import org.hibernate.persister.collection.QueryableCollection;
1313
import org.hibernate.persister.entity.PropertyMapping;
14-
import org.hibernate.type.ComponentType;
14+
import org.hibernate.type.CompositeType;
1515
import org.hibernate.type.Type;
1616

1717
/**
@@ -21,7 +21,7 @@
2121
*/
2222
public class ComponentJoin extends FromElement {
2323
private final String componentPath;
24-
private final ComponentType componentType;
24+
private final CompositeType componentType;
2525

2626
private final String componentProperty;
2727
private final String[] columns;
@@ -32,7 +32,7 @@ public ComponentJoin(
3232
FromElement origin,
3333
String alias,
3434
String componentPath,
35-
ComponentType componentType) {
35+
CompositeType componentType) {
3636
super( fromClause, origin, alias );
3737
this.componentPath = componentPath;
3838
this.componentType = componentType;
@@ -60,7 +60,7 @@ public String getComponentProperty() {
6060
return componentProperty;
6161
}
6262

63-
public ComponentType getComponentType() {
63+
public CompositeType getComponentType() {
6464
return componentType;
6565
}
6666

hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/FromElementFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.hibernate.sql.JoinType;
2323
import org.hibernate.type.AssociationType;
2424
import org.hibernate.type.CollectionType;
25-
import org.hibernate.type.ComponentType;
25+
import org.hibernate.type.CompositeType;
2626
import org.hibernate.type.EntityType;
2727
import org.hibernate.type.Type;
2828

@@ -286,7 +286,7 @@ public FromElement createEntityJoin(
286286
return elem;
287287
}
288288

289-
public FromElement createComponentJoin(ComponentType type) {
289+
public FromElement createComponentJoin(CompositeType type) {
290290

291291
// need to create a "place holder" from-element that can store the component/alias for this
292292
// component join

hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/IntoClause.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.hibernate.QueryException;
1616
import org.hibernate.internal.util.collections.ArrayHelper;
1717
import org.hibernate.persister.entity.Queryable;
18-
import org.hibernate.type.ComponentType;
18+
import org.hibernate.type.CompositeType;
1919
import org.hibernate.type.Type;
2020

2121
import antlr.collections.AST;
@@ -157,9 +157,9 @@ private void visitPropertySpecNodes(AST propertyNode, List types) {
157157
}
158158

159159
if ( !explicitIdInsertion ) {
160-
if ( persister.getIdentifierType() instanceof ComponentType ) {
160+
if ( persister.getIdentifierType() instanceof CompositeType ) {
161161
if ( componentIds == null ) {
162-
String[] propertyNames = ( (ComponentType) persister.getIdentifierType() ).getPropertyNames();
162+
String[] propertyNames = ( (CompositeType) persister.getIdentifierType() ).getPropertyNames();
163163
componentIds = new HashSet();
164164
for ( int i = 0; i < propertyNames.length; i++ ) {
165165
componentIds.add( propertyNames[i] );

hibernate-core/src/main/java/org/hibernate/loader/criteria/ComponentCollectionCriteriaInfoProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import org.hibernate.persister.collection.QueryableCollection;
1414
import org.hibernate.persister.entity.PropertyMapping;
15-
import org.hibernate.type.ComponentType;
15+
import org.hibernate.type.CompositeType;
1616
import org.hibernate.type.Type;
1717

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

32-
ComponentType componentType = (ComponentType) persister.getElementType();
32+
CompositeType componentType = (CompositeType) persister.getElementType();
3333
String[] names = componentType.getPropertyNames();
3434
Type[] types = componentType.getSubtypes();
3535

hibernate-core/src/main/java/org/hibernate/loader/plan/exec/internal/EntityLoadQueryDetails.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.hibernate.persister.entity.Joinable;
3535
import org.hibernate.persister.entity.OuterJoinLoadable;
3636
import org.hibernate.persister.entity.Queryable;
37-
import org.hibernate.type.ComponentType;
3837
import org.hibernate.type.CompositeType;
3938
import org.hibernate.type.Type;
4039

@@ -247,7 +246,7 @@ private void addKeyManyToOnesToSession(ResultSetProcessingContextImpl context, C
247246
( (Session) context.getSession() ).buildLockRequest( LockOptions.NONE ).lock( subValue );
248247
}
249248
else if ( subType.isComponentType() ) {
250-
addKeyManyToOnesToSession( context, (ComponentType) subType, subValue );
249+
addKeyManyToOnesToSession( context, (CompositeType) subType, subValue );
251250
}
252251
}
253252
}

hibernate-core/src/main/java/org/hibernate/proxy/ProxyFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface ProxyFactory {
3737
* @param setIdentifierMethod Reference to the identifier setter method;
3838
* invocation on this method should not force initialization
3939
* @param componentIdType For composite identifier types, a reference to
40-
* the {@link org.hibernate.type.ComponentType type} of the identifier
40+
* the {@link org.hibernate.type.CompositeType type} of the identifier
4141
* property; again accessing the id should generally not cause
4242
* initialization - but need to bear in mind <key-many-to-one/>
4343
* mappings.

hibernate-core/src/main/java/org/hibernate/type/AnyType.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hibernate.FetchMode;
2121
import org.hibernate.HibernateException;
2222
import org.hibernate.MappingException;
23+
import org.hibernate.PropertyNotFoundException;
2324
import org.hibernate.TransientObjectException;
2425
import org.hibernate.engine.internal.ForeignKeys;
2526
import org.hibernate.engine.jdbc.Size;
@@ -35,8 +36,6 @@
3536
import org.hibernate.proxy.HibernateProxyHelper;
3637
import org.hibernate.proxy.LazyInitializer;
3738

38-
import org.dom4j.Node;
39-
4039
/**
4140
* Handles "any" mappings
4241
*
@@ -49,9 +48,6 @@ public class AnyType extends AbstractType implements CompositeType, AssociationT
4948

5049
/**
5150
* Intended for use only from legacy {@link ObjectType} type definition
52-
*
53-
* @param discriminatorType
54-
* @param identifierType
5551
*/
5652
protected AnyType(Type discriminatorType, Type identifierType) {
5753
this( null, discriminatorType, identifierType );
@@ -375,6 +371,18 @@ public String[] getPropertyNames() {
375371
return PROPERTY_NAMES;
376372
}
377373

374+
@Override
375+
public int getPropertyIndex(String name) {
376+
if ( PROPERTY_NAMES[0].equals( name ) ) {
377+
return 0;
378+
}
379+
else if ( PROPERTY_NAMES[1].equals( name ) ) {
380+
return 1;
381+
}
382+
383+
throw new PropertyNotFoundException( "Unable to locate property named " + name + " on AnyType" );
384+
}
385+
378386
@Override
379387
public Object getPropertyValue(Object component, int i, SessionImplementor session) throws HibernateException {
380388
return i==0
@@ -415,6 +423,12 @@ public boolean[] getPropertyNullability() {
415423
return NULLABILITY;
416424
}
417425

426+
@Override
427+
public boolean hasNotNullProperty() {
428+
// both are non-nullable
429+
return true;
430+
}
431+
418432
@Override
419433
public Type[] getSubtypes() {
420434
return new Type[] {discriminatorType, identifierType };

hibernate-core/src/main/java/org/hibernate/type/ComponentType.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
import org.hibernate.tuple.component.ComponentMetamodel;
3232
import org.hibernate.tuple.component.ComponentTuplizer;
3333

34-
import org.dom4j.Element;
35-
import org.dom4j.Node;
36-
3734
/**
3835
* Handles "component" mappings
3936
*
@@ -723,6 +720,7 @@ public boolean isEmbedded() {
723720
return false;
724721
}
725722

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

818+
@Override
820819
public boolean hasNotNullProperty() {
821820
return hasNotNullProperty;
822821
}

0 commit comments

Comments
 (0)