I really want to know more about the update, export and the values that could be given to hibernate.hbm2ddl.auto
I need to know when to use the update and w
Since 5.0, you can now find those values in a dedicated Enum
: org.hibernate.boot.SchemaAutoTooling (enhanced with value NONE
since 5.2).
Or even better, since 5.1, you can also use the org.hibernate.tool.schema.Action Enum
which combines JPA 2 and "legacy" Hibernate DDL actions.
But, you cannot yet configure a DataSource
programmatically with this. It would be nicer to use this combined with org.hibernate.cfg.AvailableSettings#HBM2DDL_AUTO but the current code expect a String
value (excerpt taken from SessionFactoryBuilderImpl):
this.schemaAutoTooling = SchemaAutoTooling.interpret( (String) configurationSettings.get( AvailableSettings.HBM2DDL_AUTO ) );
… and internal enum
values of both org.hibernate.boot.SchemaAutoToolingand org.hibernate.tool.schema.Action aren't exposed publicly.
Hereunder, a sample programmatic DataSource
configuration (used in ones of my Spring Boot applications) which use a gambit thanks to .name().toLowerCase()
but it only works with values without dash (not create-drop
for instance):
@Bean(name = ENTITY_MANAGER_NAME)
public LocalContainerEntityManagerFactoryBean internalEntityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier(DATA_SOURCE_NAME) DataSource internalDataSource) {
Map properties = new HashMap<>();
properties.put(AvailableSettings.HBM2DDL_AUTO, SchemaAutoTooling.CREATE.name().toLowerCase());
properties.put(AvailableSettings.DIALECT, H2Dialect.class.getName());
return builder
.dataSource(internalDataSource)
.packages(JpaModelsScanEntry.class, Jsr310JpaConverters.class)
.persistenceUnit(PERSISTENCE_UNIT_NAME)
.properties(properties)
.build();
}