Hi,

a composite-id composed by a key-many-to-one component witch in turn has a 
composite-id, causes a "broken mapping error...".

I found that this is due to the code in postInstantiate method of EntityPersister 
class:

if ( idType.isComponentType() ) {
        AbstractComponentType actype = (AbstractComponentType) idType;
        String[] props = actype.getPropertyNames();
        if (props.length!=columns.length) throw new MappingException("broken mapping 
for: " + getClassName() + '.' + path);
        for ( int i=0; i<props.length; i++ ) {
                String subidpath = idpath + '.' + props[i];
                columnNamesByPropertyPath.put( subidpath, new String[] { columns[i] } 
);
                mods.put( subidpath, actype.getSubtypes()[i] );
        }
}

Here, props.length (the number of properties in the composite-id) differs from 
columns.length (the number of columns declared inside the composite-id) if one or more 
of the components is a key-many-to-one with more than one column.
The code is the same in Hibernate1.2.3 and hb2.
I think that the correct check should be:

if (actype.getColumnSpan(factory) != columns.length)
        throw new MappingException("broken mapping for: " + getClassName() + '.' + 
path);

if (props.length!=columns.length)
        log.info("Multicolumn component. What should I do now?");

This avoids the exception raising, but the subsequent code will fail to map paths with 
columns.
A first solution could be to calculate the number of columns for each component, 
grabbing from columns[] array the exact number of columns instead of just one.
However this solution didn't handle a composite-id in which key-many-to-one components 
had more than one column and some columns were shared among them (in the legacy data 
world it happens...)

Could someone confirm this? Given some directions about this topic I could try to 
develop a patch (if needed)

stefano


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel


Reply via email to