HHH-12955 Avoid a warn message by updating SchemaAutoTooling values
Some valid values of hibernate.hbm2ddl.auto were not present in this class, whereas they should have been.
This commit is contained in:
parent
653b123276
commit
2c041447c2
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.boot;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
|
@ -24,6 +25,14 @@ public enum SchemaAutoTooling {
|
|||
* schema on SessionFactory shutdown.
|
||||
*/
|
||||
CREATE_DROP( "create-drop" ),
|
||||
/**
|
||||
* Create the schema on SessionFactory startup.
|
||||
*/
|
||||
CREATE_ONLY( "create-only" ),
|
||||
/**
|
||||
* Drop the schema and don't recreate it.
|
||||
*/
|
||||
DROP( "drop" ),
|
||||
/**
|
||||
* Update (alter) the schema on SessionFactory startup.
|
||||
*/
|
||||
|
@ -59,10 +68,16 @@ public enum SchemaAutoTooling {
|
|||
else if ( CREATE_DROP.externalForm.equals( configurationValue ) ) {
|
||||
return CREATE_DROP;
|
||||
}
|
||||
else if ( CREATE_ONLY.externalForm.equals( configurationValue ) ) {
|
||||
return CREATE_ONLY;
|
||||
}
|
||||
else if ( DROP.externalForm.equals( configurationValue ) ) {
|
||||
return DROP;
|
||||
}
|
||||
else {
|
||||
throw new HibernateException(
|
||||
"Unrecognized hbm2ddl_auto value : " + configurationValue
|
||||
+ ". Supported values include 'create', 'create-drop', 'update', 'none' and 'validate'."
|
||||
"Unrecognized " + AvailableSettings.HBM2DDL_AUTO + " value: " + configurationValue
|
||||
+ ". Supported values include 'create', 'create-drop', 'create-only', 'drop', 'update', 'none' and 'validate'."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -254,7 +254,8 @@ public final class Settings {
|
|||
|
||||
public boolean isAutoCreateSchema() {
|
||||
return sessionFactoryOptions.getSchemaAutoTooling() == SchemaAutoTooling.CREATE
|
||||
|| sessionFactoryOptions.getSchemaAutoTooling() == SchemaAutoTooling.CREATE_DROP;
|
||||
|| sessionFactoryOptions.getSchemaAutoTooling() == SchemaAutoTooling.CREATE_DROP
|
||||
|| sessionFactoryOptions.getSchemaAutoTooling() == SchemaAutoTooling.CREATE_ONLY;
|
||||
}
|
||||
|
||||
public boolean isAutoDropSchema() {
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package org.hibernate.test.schemaupdate;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
|
||||
import org.hibernate.boot.internal.SessionFactoryOptionsBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.jpa.boot.spi.Bootstrap;
|
||||
import org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter;
|
||||
import org.hibernate.jpa.test.mapping.ColumnWithExplicitReferenceToPrimaryTableTest.AnEntity;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||
import org.hibernate.testing.logger.Triggerable;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
public class Hbm2ddlCreateOnlyTest {
|
||||
|
||||
@Rule
|
||||
public LoggerInspectionRule logInspection = new LoggerInspectionRule( Logger.getMessageLogger(
|
||||
CoreMessageLogger.class, SessionFactoryOptionsBuilder.class.getName() ) );
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12955")
|
||||
public void testColumnAnnotationWithExplicitReferenceToPrimaryTable() {
|
||||
final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() {
|
||||
@Override
|
||||
public List<String> getManagedClassNames() {
|
||||
return Arrays.asList( AnEntity.class.getName() );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
final Map settings = new HashMap();
|
||||
settings.put( AvailableSettings.HBM2DDL_AUTO, "create-only" );
|
||||
|
||||
EntityManagerFactory emf = null;
|
||||
try {
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "Unrecognized " + AvailableSettings.HBM2DDL_AUTO + " value" );
|
||||
|
||||
emf = Bootstrap.getEntityManagerFactoryBuilder( pu, settings ).build();
|
||||
emf.createEntityManager();
|
||||
|
||||
assertFalse( triggerable.wasTriggered() );
|
||||
}
|
||||
finally {
|
||||
if ( emf != null ) {
|
||||
emf.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue