[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6238) Issue in the TypeHelper.replaceAssociations(): component properties are not processed properly

Yury Mishchenko (JIRA) noreply at atlassian.com
Fri May 20 08:54:24 EDT 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6238?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=42364#action_42364 ] 

Yury Mishchenko commented on HHH-6238:
--------------------------------------

The fix actually does not fix it. It causes troubles in different cases. It also looks like the problem is in a different place. I have solvedmy initial issue by assigning an empty collections to component properties.

> Issue in the TypeHelper.replaceAssociations(): component properties are not processed properly
> ----------------------------------------------------------------------------------------------
>
>                 Key: HHH-6238
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6238
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.6.5
>            Reporter: Yury Mishchenko
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> There seems to be an issue in the org.hibernate.type.TypeHelper.replaceAssociations() method. You can see in the source (see below) that it does not do replacement properly for components properties.
> It does execute replacement for component properties but it does not apply results to the target. Thus it returns the target unchanged. I found this issue when executing a merge on an entity having a component property with an embedded set. The embedded set is never persisted. I think the fix is very simple: one needs to use results of the replacement and update the target properties. Is it feasible for the 3.6.5?
> {code}
> 	public static Object[] replaceAssociations(
> 			final Object[] original,
> 			final Object[] target,
> 			final Type[] types,
> 			final SessionImplementor session,
> 			final Object owner,
> 			final Map copyCache,
> 			final ForeignKeyDirection foreignKeyDirection) {
> 		Object[] copied = new Object[original.length];
> 		for ( int i = 0; i < types.length; i++ ) {
> 			if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
> 					|| original[i] == BackrefPropertyAccessor.UNKNOWN ) {
> 				copied[i] = target[i];
> 			}
> 			else if ( types[i].isComponentType() ) {
> 				// need to extract the component values and check for subtype replacements...
> 				CompositeType componentType = ( CompositeType ) types[i];
> 				Type[] subtypes = componentType.getSubtypes();
> 				Object[] origComponentValues = original[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( original[i], session );
> 				Object[] targetComponentValues = target[i] == null ? new Object[subtypes.length] : componentType.getPropertyValues( target[i], session );
> // PROBLEM: Results of the replace is not used!!! Instead they should be used for updating target[i] properties!!!
> 				replaceAssociations( origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection );
> 				copied[i] = target[i];
> 			}
> 			else if ( !types[i].isAssociationType() ) {
> 				copied[i] = target[i];
> 			}
> 			else {
> 				copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache, foreignKeyDirection );
> 			}
> 		}
> 		return copied;
> 	}
> {code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list