|
From: <hib...@li...> - 2006-05-30 14:16:13
|
Author: ste...@jb...
Date: 2006-05-30 10:15:54 -0400 (Tue, 30 May 2006)
New Revision: 9963
Modified:
trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
Log:
HHH-1791: incorrect handling of generated="insert" and update="false" combo
Modified: trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-05-30 13:56:00 UTC (rev 9962)
+++ trunk/Hibernate3/src/org/hibernate/cfg/HbmBinder.java 2006-05-30 14:15:54 UTC (rev 9963)
@@ -1209,28 +1209,44 @@
Attribute generatedNode = node.attribute( "generated" );
String generationName = generatedNode == null ? null : generatedNode.getValue();
PropertyGeneration generation = PropertyGeneration.parse( generationName );
- // values marked as "generated=always" or "generated=insert" cannot also be marked
- // insertable and/or updateable.
- // insertable and updateable are the defaults, so if the user did not specify
- // just override; otherwise, throw an exception
+ property.setGeneration( generation );
+
if ( generation == PropertyGeneration.ALWAYS || generation == PropertyGeneration.INSERT ) {
- if ( insertNode != null && property.isInsertable() ) {
- throw new MappingException(
- "cannot specify both insert=\"true\" and generated=\"" + generation.getName() +
- "\" for property: " +
- propName
+ // 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=\"" + generation.getName() +
+ "\" for property: " +
+ propName
);
- }
- if ( updateNode != null && property.isUpdateable() && generation == PropertyGeneration.ALWAYS ) {
- throw new MappingException(
- "cannot specify both update=\"true\" and generated=\"" + generation.getName() +
- "\" for property: " +
- propName
+ }
+ }
+
+ // properties generated on update can never be updateable...
+ if ( property.isUpdateable() && generation == PropertyGeneration.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=\"" + generation.getName() +
+ "\" for property: " +
+ propName
);
- }
- property.setInsertable( false );
- property.setUpdateable( generation != PropertyGeneration.ALWAYS );
- property.setGeneration( generation );
+ }
+ }
}
boolean isLazyable = "property".equals( node.getName() ) ||
|