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 final InDatabaseValueGenerationStrategy generationStrategy
= entityMetamodel.getInDatabaseValueGenerationStrategies()[propertyNumber]; = entityMetamodel.getInDatabaseValueGenerationStrategies()[propertyNumber];
return generationStrategy != null 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) { private boolean isReadRequired(ValueGeneration valueGeneration, GenerationTiming matchTiming) {
return valueGeneration != null && return valueGeneration != null &&
valueGeneration.getValueGenerator() == 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 return
(matchTiming == GenerationTiming.INSERT && valueGeneration.getGenerationTiming().includesInsert()) || (matchTiming == GenerationTiming.INSERT && timing.includesInsert()) ||
(matchTiming == GenerationTiming.ALWAYS && valueGeneration.getGenerationTiming() (matchTiming == GenerationTiming.ALWAYS && timing.includesUpdate());
.includesUpdate());
} }
public String getIdentifierPropertyName() { public String getIdentifierPropertyName() {

View File

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

View File

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