With hbm2ddl.auto=update on Postgresql, columns for properties persisted as timestamps (like Instant, OffsetDateTime, LocalDateTime, …) are updated on every startup, even if the alter statement does not perform any actual change. hbm2ddl.auto=validate does not detect any problem. This did not happen on 6.1.7 (because it did not have the capability to update existing columns anyway). Sample My entity:
@Entity
@Getter
@Setter
public class Test {
@Id
private String id;
private Instant instant;
private OffsetDateTime offsetDateTime;
private ZonedDateTime zonedDateTime;
private LocalDateTime localDateTime;
private Date date;
}
Startup logs (even when columns already exist with the right type):
Quick analysis (using 6.2.0.CR4) With hbm2ddl.auto=update: StandardTableMigrator#sqlAlterStrings checks both type and length
With hbm2ddl.auto=validate: AbstractSchemaValidator#validateColumnType only checks the type (which matches)
So the problem is in ColumnDefinitions.hasMatchingLength:
final int actualSize = columnInformation.getColumnSize();
if ( actualSize == 0 ) {
return true;
}
else {
final Size size = column.getColumnSize( dialect, metadata );
final Long requiredLength = size.getLength();
final Integer requiredPrecision = size.getPrecision();
return requiredLength != null && requiredLength == actualSize
|| requiredPrecision != null && requiredPrecision == actualSize
|| requiredPrecision == null && requiredLength == null;
}
For a timestamp with zone column:
- actualSize = 35 (no idea why)
- requiredLength is null
- requiredPrecision = 6
- ==> requiredPrecision != null && requiredPrecision == actualSize is false
|