SchemaManager.validation() should throw SchemaValidationException

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-12 10:32:23 +02:00 committed by Steve Ebersole
parent 5caa0b2735
commit bf6a66d9ce
3 changed files with 23 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.relational.SchemaManager;
import org.hibernate.tool.schema.Action;
import org.hibernate.tool.schema.spi.SchemaManagementException;
import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator;
import java.util.HashMap;
@ -92,7 +93,12 @@ public class SchemaManagerImpl implements SchemaManager {
@Override
public void validate() throws SchemaValidationException {
validateMappedObjects();
try {
validateMappedObjects();
}
catch ( SchemaManagementException sme ) {
throw new SchemaValidationException( sme.getMessage(), sme );
}
}
@Override

View File

@ -10,6 +10,7 @@ import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SchemaValidationException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
@ -59,6 +60,13 @@ public class SchemaManagerDefaultSchemaTest {
catch (SchemaManagementException e) {
assertTrue( e.getMessage().contains("ForTesting") );
}
try {
factory.getSchemaManager().validate();
fail();
}
catch (SchemaValidationException e) {
assertTrue( e.getMessage().contains("ForTesting") );
}
}
@Entity(name="BookForTesting")

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.orm.test.schemamanager;
import jakarta.persistence.SchemaValidationException;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.tool.schema.spi.SchemaManagementException;
@ -65,6 +66,13 @@ public class SchemaManagerExplicitSchemaTest {
catch (SchemaManagementException e) {
assertTrue( e.getMessage().contains("ForTesting") );
}
try {
factory.getSchemaManager().validate();
fail();
}
catch (SchemaValidationException e) {
assertTrue( e.getMessage().contains("ForTesting") );
}
}
@Entity(name="BookForTesting")