Attribute generatedNode = node.attribute( "generated" );
String generationName = generatedNode == null ? null : generatedNode.getValue();
// Handle generated properties.
GenerationTiming generationTiming = GenerationTiming.parseFromName( generationName );
if ( generationTiming == GenerationTiming.ALWAYS || generationTiming == GenerationTiming.INSERT ) {
// we had generation specified...
// HBM only supports "database generated values"
property.setValueGenerationStrategy( new GeneratedValueGeneration( generationTiming ) );
// generated properties can *never* be insertable...
if ( property.isInsertable() ) {
if ( insertNode == null ) {
// insertable simply because that is the user did not specify
// anything; just override it
property.setInsertable( false );
}
else {
// the user specifically supplied insert="true",
// which constitutes an illegal combo
throw new MappingException(
"cannot specify both insert=\"true\" and generated=\"" + generationTiming.name().toLowerCase() +
"\" for property: " +
propName
);
}
}
// properties generated on update can never be updateable...
if ( property.isUpdateable() && generationTiming == GenerationTiming.ALWAYS ) {
if ( updateNode == null ) {
// updateable only because the user did not specify
// anything; just override it
property.setUpdateable( false );
}
else {
// the user specifically supplied update="true",
// which constitutes an illegal combo
throw new MappingException(
"cannot specify both update=\"true\" and generated=\"" + generationTiming.name().toLowerCase() +
"\" for property: " +
propName
);
}
}