I tried evaluating the code-path of Hibernate 4.3 for building the EntityAttribute for an association and it looks like this code works fine, with the same data:
Code:
public static NonIdentifierAttribute buildEntityBasedAttribute(EntityPersister persister, SessionFactoryImplementor sessionFactory, int attributeNumber, Property property, boolean lazyAvailable) {
Type type = property.getValue().getType();
PropertyFactory.NonIdentifierAttributeNature nature = decode(type);
boolean alwaysDirtyCheck = type.isAssociationType() && ((AssociationType)type).isAlwaysDirtyChecked();
switch(PropertyFactory.SyntheticClass_1.$SwitchMap$org$hibernate$tuple$PropertyFactory$NonIdentifierAttributeNature[nature.ordinal()]) {
case 1:
return new EntityBasedBasicAttribute(persister, sessionFactory, attributeNumber, property.getName(), type, (new Builder()).setLazy(lazyAvailable && property.isLazy()).setInsertable(property.isInsertable()).setUpdateable(property.isUpdateable()).setValueGenerationStrategy(property.getValueGenerationStrategy()).setNullable(property.isOptional()).setDirtyCheckable(alwaysDirtyCheck || property.isUpdateable()).setVersionable(property.isOptimisticLocked()).setCascadeStyle(property.getCascadeStyle()).setFetchMode(property.getValue().getFetchMode()).createInformation());
case 2:
return new EntityBasedCompositionAttribute(persister, sessionFactory, attributeNumber, property.getName(), (CompositeType)type, (new Builder()).setLazy(lazyAvailable && property.isLazy()).setInsertable(property.isInsertable()).setUpdateable(property.isUpdateable()).setValueGenerationStrategy(property.getValueGenerationStrategy()).setNullable(property.isOptional()).setDirtyCheckable(alwaysDirtyCheck || property.isUpdateable()).setVersionable(property.isOptimisticLocked()).setCascadeStyle(property.getCascadeStyle()).setFetchMode(property.getValue().getFetchMode()).createInformation());
case 3:
case 4:
case 5:
return new EntityBasedAssociationAttribute(persister, sessionFactory, attributeNumber, property.getName(), (AssociationType)type, (new Builder()).setLazy(lazyAvailable && property.isLazy()).setInsertable(property.isInsertable()).setUpdateable(property.isUpdateable()).setValueGenerationStrategy(property.getValueGenerationStrategy()).setNullable(property.isOptional()).setDirtyCheckable(alwaysDirtyCheck || property.isUpdateable()).setVersionable(property.isOptimisticLocked()).setCascadeStyle(property.getCascadeStyle()).setFetchMode(property.getValue().getFetchMode()).createInformation());
default:
throw new HibernateException("Internal error");
}
}
however in hibernate 5.2, when i tried digging in deep, all i can find out is that it breaks in the following function:
Code:
public static PluralAttribute.CollectionType determineCollectionType(Class javaType) {
if ( java.util.List.class.isAssignableFrom( javaType ) ) {
return PluralAttribute.CollectionType.LIST;
}
else if ( java.util.Set.class.isAssignableFrom( javaType ) ) {
return PluralAttribute.CollectionType.SET;
}
else if ( java.util.Map.class.isAssignableFrom( javaType ) ) {
return PluralAttribute.CollectionType.MAP;
}
else if ( java.util.Collection.class.isAssignableFrom( javaType ) ) {
return PluralAttribute.CollectionType.COLLECTION;
}
else if ( javaType.isArray() ) {
return PluralAttribute.CollectionType.LIST;
}
else {
throw new IllegalArgumentException( "Expecting collection type [" + javaType.getName() + "]" );
}
}
the input to the above function is
org.hibernate.type.BagType since the ReporteesArr attribute is a collection kind of property but still it breaks by throwing the IllegalArguementException.
I am a bit new to this, but able to understand a bit of complexity. Can you help me out with the steps to debug this?
I specifically checked that the input values to both the functions are same.