Felix Ullrich commented on Bug HHH-7625

I've got the same problem and in our database-schema its really common to declare the foreignkey as part of composite primary key in the childobject.

After extending the searchMappedBy in the CollectionMetadataGenerator it was possible to add new childobjects to the collection. The history was written correct.
Deleting them or selecting a specific revision of the parent with the AuditReader and retriviing the childs was not possible. That's the code I used:

CollectionMetadataGenerator .java
private String searchMappedBy(PersistentClass referencedClass, Collection collectionValue) {                                         
	Iterator<Property> assocClassProps = referencedClass.getPropertyIterator();                                                      
	while (assocClassProps.hasNext()) {                                                                                              
		Property property = assocClassProps.next();                                                                                  
                                                                                                                                     
		if (Tools.iteratorsContentEqual(property.getValue().getColumnIterator(), collectionValue.getKey().getColumnIterator())) {    
			return property.getName();                                                                                               
		}                                                                                                                            
	}                                                                                                                                
               
        // check if the field is part of the primary key                                                                                                              
	Iterator<Component> assocClassComp = referencedClass.getKeyClosureIterator();                                                    
	while (assocClassComp.hasNext()) {                                                                                               
		Component component = assocClassComp.next();                                                                                 
                                                                                                                                     
		assocClassProps = component.getPropertyIterator();                                                                           
		while (assocClassProps.hasNext()) {                                                                                          
			Property property = assocClassProps.next();                                                                              
                                                                                                                                     
			if (Tools.iteratorsContentEqual(property.getValue().getColumnIterator(), collectionValue.getKey().getColumnIterator())) {
				return property.getName();                                                                                           
			}                                                                                                                        
		}                                                                                                                            
	}                                                                                                                                
                                                                                                                                     
	return null;                                                                                                                     
}
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira