HHH-9745 - ClassCastException in hbm2ddl update and validate
This commit is contained in:
parent
6d0549b448
commit
14fc8859fe
|
@ -46,21 +46,34 @@ public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareS
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialect buildDialect(Map configValues, DialectResolutionInfoSource resolutionInfoSource) throws HibernateException {
|
public Dialect buildDialect(Map configValues, DialectResolutionInfoSource resolutionInfoSource) throws HibernateException {
|
||||||
final String dialectName = (String) configValues.get( AvailableSettings.DIALECT );
|
final Object dialectReference = configValues.get( AvailableSettings.DIALECT );
|
||||||
if ( !StringHelper.isEmpty( dialectName ) ) {
|
if ( !isEmpty( dialectReference ) ) {
|
||||||
return constructDialect( dialectName );
|
return constructDialect( dialectReference );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return determineDialect( resolutionInfoSource );
|
return determineDialect( resolutionInfoSource );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dialect constructDialect(String dialectName) {
|
@SuppressWarnings("SimplifiableIfStatement")
|
||||||
|
private boolean isEmpty(Object dialectReference) {
|
||||||
|
if ( dialectReference != null ) {
|
||||||
|
// the referenced value is not null
|
||||||
|
if ( dialectReference instanceof String ) {
|
||||||
|
// if it is a String, it might still be empty though...
|
||||||
|
return StringHelper.isEmpty( (String) dialectReference );
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dialect constructDialect(Object dialectReference) {
|
||||||
final Dialect dialect;
|
final Dialect dialect;
|
||||||
try {
|
try {
|
||||||
dialect = strategySelector.resolveStrategy( Dialect.class, dialectName );
|
dialect = strategySelector.resolveStrategy( Dialect.class, dialectReference );
|
||||||
if ( dialect == null ) {
|
if ( dialect == null ) {
|
||||||
throw new HibernateException( "Unable to construct requested dialect [" + dialectName+ "]" );
|
throw new HibernateException( "Unable to construct requested dialect [" + dialectReference + "]" );
|
||||||
}
|
}
|
||||||
return dialect;
|
return dialect;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +81,7 @@ public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareS
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new HibernateException( "Unable to construct requested dialect [" + dialectName+ "]", e );
|
throw new HibernateException( "Unable to construct requested dialect [" + dialectReference + "]", e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,6 @@ public class SequenceInformationExtractorNoOpImpl implements SequenceInformation
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Iterable<SequenceInformation> extractMetadata(ExtractionContext extractionContext) throws SQLException {
|
public Iterable<SequenceInformation> extractMetadata(ExtractionContext extractionContext) throws SQLException {
|
||||||
return (Iterable<SequenceInformation>) Collections.emptyList().iterator();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.test.schemaupdate;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.boot.MetadataSources;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.dialect.H2Dialect;
|
||||||
|
import org.hibernate.tool.hbm2ddl.SchemaExport;
|
||||||
|
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
|
||||||
|
import org.hibernate.tool.hbm2ddl.Target;
|
||||||
|
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
|
||||||
|
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
|
||||||
|
|
||||||
|
import org.hibernate.testing.RequiresDialect;
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regression test fr a bug in org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl
|
||||||
|
*
|
||||||
|
* @author Steve Ebersole
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
*/
|
||||||
|
@TestForIssue( jiraKey = "HHH-9745" )
|
||||||
|
public class SequenceReadingTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSequenceReading() {
|
||||||
|
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||||
|
.applySetting( AvailableSettings.DIALECT, MyExtendedH2Dialect.class )
|
||||||
|
.build();
|
||||||
|
try {
|
||||||
|
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||||
|
.addAnnotatedClass( MyEntity.class )
|
||||||
|
.buildMetadata();
|
||||||
|
metadata.validate();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// try to update the schema
|
||||||
|
new SchemaUpdate( metadata ).execute( Target.EXPORT );
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
// clean up
|
||||||
|
new SchemaExport( metadata ).drop( Target.EXPORT );
|
||||||
|
}
|
||||||
|
catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
StandardServiceRegistryBuilder.destroy( ssr );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An integral piece of the bug is Dialects which to not support sequence, so lets trick the test
|
||||||
|
*/
|
||||||
|
public static class MyExtendedH2Dialect extends H2Dialect {
|
||||||
|
@Override
|
||||||
|
public SequenceInformationExtractor getSequenceInformationExtractor() {
|
||||||
|
return SequenceInformationExtractorNoOpImpl.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getQuerySequencesString() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(name = "MyEntity")
|
||||||
|
@Table(name = "my_entity")
|
||||||
|
public static class MyEntity {
|
||||||
|
@Id
|
||||||
|
public Integer id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue