It seems that in-DB generated columns are not passed into the Indentity Insert query of the entity persister. For example the FunctionCreationTimestamp from the http://docs.jboss.org/hibernate/orm/4.3/topical/html/generated/GeneratedValues.html documentation, does not insert on an update for an entity with a @Id @GeneratedValue(strategy = GenerationType. AUTO IDENTITY ) Long id column. It does work however with GenerationType.AUTO.
The problem seems to be the inconsistency between generateIdentityInsertString and generateInsertString .
One adds the normal properties as follows:
{code:java} // add normal properties for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { // the incoming 'includeProperty' array only accounts for insertable defined at the root level, it // does not account for partially generated composites etc. We also need to account for generation // values if ( isPropertyOfTable( i, j ) ) { if ( !lobProperties.contains( i ) ) { final InDatabaseValueGenerationStrategy generationStrategy = entityMetamodel.getInDatabaseValueGenerationStrategies()[i]; if ( generationStrategy != null && generationStrategy.getGenerationTiming().includesInsert() ) { if ( generationStrategy.referenceColumnsInSql() ) { final String[] values; if ( generationStrategy.getReferencedColumnValues() == null ) { values = propertyColumnWriters[i]; } else { final int numberOfColumns = propertyColumnWriters[i].length; values = new String[numberOfColumns]; for ( int x = 0; x < numberOfColumns; x++ ) { if ( generationStrategy.getReferencedColumnValues()[x] != null ) { values[x] = generationStrategy.getReferencedColumnValues()[x]; } else { values[x] = propertyColumnWriters[i][x]; } } } insert.addColumns( getPropertyColumnNames( i ), propertyColumnInsertable[i], values ); } } else if ( includeProperty[i] ) { insert.addColumns( getPropertyColumnNames( i ), propertyColumnInsertable[i], propertyColumnWriters[i] ); } } } } {code}
Whereas the others does something way less sophisticated:
{code:java} // add normal properties except lobs for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) { if ( includeProperty[i] && isPropertyOfTable( i, 0 ) && !lobProperties.contains( i ) ) { // this property belongs on the table and is to be inserted insert.addColumns( getPropertyColumnNames( i ), propertyColumnInsertable[i], propertyColumnWriters[i] ); } } {code}
Is there a technical reason why INSERT time in-db generated values are not supported with Identity insert, or this this a slight overlook? |
|