The problem seems to be in EntityType because it's replacing the children object with all the values to be merged with a fresh instance of the class, which makes no sense and causes the merge operation to fail in to merge children values (they get all lost)
at line 283:
if ( session.getContextEntityIdentifier( original ) == null &&
ForeignKeys.isTransient( associatedEntityName, original, Boolean.FALSE, session ) ) {
final Object copy = session.getFactory().getEntityPersister( associatedEntityName )
.instantiate( null, session );
//TODO: should this be Session.instantiate(Persister, ...)?
copyCache.put( original, copy );
return copy;
}
—
copyCache.put( original, copy ); <-- the original key gets a fresh entity with no attributes, so all its values are lost and consequently don't get merged
test case:
@Test
public void shouldCascadeToChildren() throws Exception {
Parent parent = aParent();
parent.addChild(aChild());
repository.add(parent);
List<Child> children = repository.getChild(parent);
Assert.assertThat(children, hasItem(parent.getChildren().get(0)));
}
|