[HHH-4552] generatedvalue for compositekeys are now parsed and added to the id properties

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18629 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Ståle W. Pedersen 2010-01-26 13:39:26 +00:00
parent 41ad6c01fd
commit 2adcb4d926
2 changed files with 18 additions and 17 deletions

View File

@ -2100,6 +2100,22 @@ public final class
new HashMap<String, IdGenerator>(), entityBinder, isIdentifierMapper, isComponentEmbedded,
inSecondPass, mappings, inheritanceStatePerClass
);
XProperty property = propertyAnnotatedElement.getProperty();
if(property.isAnnotationPresent(GeneratedValue.class) &&
property.isAnnotationPresent(Id.class))
{
//clone classGenerator and override with local values
HashMap<String, IdGenerator> localGenerators = (HashMap<String, IdGenerator>) new HashMap<String, IdGenerator>();
localGenerators.putAll( buildLocalGenerators( property, mappings ) );
GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
String generatorType = generatedValue != null ? generatorType( generatedValue.strategy() ) : "assigned";
String generator = generatedValue != null ? generatedValue.generator() : BinderHelper.ANNOTATION_STRING_DEFAULT;
BinderHelper.makeIdGenerator( (SimpleValue) comp.getProperty(property.getName()).getValue(), generatorType, generator, mappings, localGenerators);
}
}
return comp;
}
@ -2120,21 +2136,6 @@ public final class
return comp;
}
private static void bindId(
String generatorType, String generatorName,
PropertyData inferredData, Ejb3Column[] columns, PropertyHolder propertyHolder,
Map<String, IdGenerator> localGenerators,
boolean isComposite,
AccessType propertyAccessor, EntityBinder entityBinder, boolean isEmbedded,
boolean isIdentifierMapper, ExtendedMappings mappings,
Map<XClass, InheritanceState> inheritanceStatePerClass
) {
bindId(generatorType, generatorName, inferredData, null, columns, propertyHolder,
localGenerators, isComposite, propertyAccessor, entityBinder,
isEmbedded, isIdentifierMapper, mappings, inheritanceStatePerClass);
}
private static void bindId(
String generatorType, String generatorName, PropertyData inferredData,
PropertyData baseInferredData, Ejb3Column[] columns, PropertyHolder propertyHolder,

View File

@ -75,7 +75,7 @@ public class IdClassGeneratedValueTest extends TestCase {
s = openSession();
s.beginTransaction();
List<Simple> simpleList = s.createQuery( "select s from Simple2 s" ).list();
List<Simple2> simpleList = s.createQuery( "select s from Simple2 s" ).list();
assertEquals( simpleList.size(), 2 );
s1 = ( Simple2 ) s.load( Simple2.class, new SimplePK( s1Id1, 2L ) );
assertEquals( s1.getQuantity(), 10 );
@ -101,7 +101,7 @@ public class IdClassGeneratedValueTest extends TestCase {
s = openSession();
s.beginTransaction();
List<Simple> simpleList = s.createQuery( "select m from Multiple m" ).list();
List<Multiple> simpleList = s.createQuery( "select m from Multiple m" ).list();
assertEquals( simpleList.size(), 2 );
m1 = ( Multiple ) s.load( Multiple.class, new MultiplePK( m1Id1, m1Id2, 2L ) );
assertEquals( m1.getQuantity(), 10 );