HHH-8784 @Generated(ALWAYS) w/ DDL default not inserting

This commit is contained in:
Brett Meyer 2013-12-09 14:02:39 -05:00
parent 3883d7ca2d
commit 46aeb988c8
3 changed files with 17 additions and 8 deletions

View File

@ -1716,7 +1716,7 @@ public abstract class AbstractEntityPersister
final InDatabaseValueGenerationStrategy generationStrategy
= entityMetamodel.getInDatabaseValueGenerationStrategies()[propertyNumber];
return generationStrategy != null
&& generationStrategy.getGenerationTiming() == generationTimingToMatch;
&& timingsMatch( generationStrategy.getGenerationTiming(), generationTimingToMatch );
}
}
);
@ -4899,14 +4899,13 @@ public abstract class AbstractEntityPersister
private boolean isReadRequired(ValueGeneration valueGeneration, GenerationTiming matchTiming) {
return valueGeneration != null &&
valueGeneration.getValueGenerator() == null &&
timingsMatch( valueGeneration, matchTiming );
timingsMatch( valueGeneration.getGenerationTiming(), matchTiming );
}
private boolean timingsMatch(ValueGeneration valueGeneration, GenerationTiming matchTiming) {
private boolean timingsMatch(GenerationTiming timing, GenerationTiming matchTiming) {
return
(matchTiming == GenerationTiming.INSERT && valueGeneration.getGenerationTiming().includesInsert()) ||
(matchTiming == GenerationTiming.ALWAYS && valueGeneration.getGenerationTiming()
.includesUpdate());
(matchTiming == GenerationTiming.INSERT && timing.includesInsert()) ||
(matchTiming == GenerationTiming.ALWAYS && timing.includesUpdate());
}
public String getIdentifierPropertyName() {

View File

@ -44,7 +44,7 @@ public class GeneratedTest extends BaseCoreFunctionalTestCase {
s.persist( antenna );
assertNull( antenna.latitude );
assertNull( antenna.longitude );
tx.rollback();
tx.commit();
s.close();
}

View File

@ -66,6 +66,7 @@ public class DefaultGeneratedValueTest extends BaseCoreFunctionalTestCase {
s.beginTransaction();
TheEntity theEntity = new TheEntity( 1 );
assertNull( theEntity.createdDate );
assertNull( theEntity.alwaysDate );
assertNull( theEntity.vmCreatedDate );
assertNull( theEntity.vmCreatedSqlDate );
assertNull( theEntity.vmCreatedSqlTime );
@ -74,6 +75,7 @@ public class DefaultGeneratedValueTest extends BaseCoreFunctionalTestCase {
s.save( theEntity );
//TODO: Actually the values should be non-null after save
assertNull( theEntity.createdDate );
assertNull( theEntity.alwaysDate );
assertNull( theEntity.vmCreatedDate );
assertNull( theEntity.vmCreatedSqlDate );
assertNull( theEntity.vmCreatedSqlTime );
@ -83,18 +85,21 @@ public class DefaultGeneratedValueTest extends BaseCoreFunctionalTestCase {
s.close();
assertNotNull( theEntity.createdDate );
assertNotNull( theEntity.alwaysDate );
assertEquals( "Bob", theEntity.name );
s = openSession();
s.beginTransaction();
theEntity = (TheEntity) s.get( TheEntity.class, 1 );
assertNotNull( theEntity.createdDate );
assertNotNull( theEntity.alwaysDate );
assertNotNull( theEntity.vmCreatedDate );
assertNotNull( theEntity.vmCreatedSqlDate );
assertNotNull( theEntity.vmCreatedSqlTime );
assertNotNull( theEntity.vmCreatedSqlTimestamp );
assertEquals( "Bob", theEntity.name );
theEntity.lastName = "Smith";
s.delete( theEntity );
s.getTransaction().commit();
s.close();
@ -131,7 +136,7 @@ public class DefaultGeneratedValueTest extends BaseCoreFunctionalTestCase {
s = openSession();
s.beginTransaction();
theEntity = (TheEntity) session.get( TheEntity.class, 1 );
theEntity = (TheEntity) s.get( TheEntity.class, 1 );
assertEquals( "Creation timestamp should not change on update", created, theEntity.vmCreatedSqlTimestamp );
assertTrue( "Update timestamp should have changed due to update", theEntity.updated.after( updated ) );
@ -157,6 +162,11 @@ public class DefaultGeneratedValueTest extends BaseCoreFunctionalTestCase {
@Column( nullable = false )
private Date createdDate;
@Generated( GenerationTime.ALWAYS )
@ColumnDefault( "CURRENT_TIMESTAMP" )
@Column( nullable = false )
private Calendar alwaysDate;
@CreationTimestamp
private Date vmCreatedDate;