mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 00:24:57 +00:00
Adapt tests and skips for H2 2.0.202+
This commit is contained in:
parent
6feb33f4e1
commit
fb749b6b32
@ -23,33 +23,32 @@
|
||||
import org.hibernate.annotations.ColumnTransformer;
|
||||
import org.hibernate.annotations.NaturalId;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@Jpa(annotatedClasses = {
|
||||
FetchingTest.Department.class,
|
||||
FetchingTest.Employee.class,
|
||||
FetchingTest.Project.class
|
||||
})
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
public class FetchingTest extends BaseEntityManagerFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Department.class,
|
||||
Employee.class,
|
||||
Project.class
|
||||
};
|
||||
}
|
||||
@SkipForDialect(dialectClass = H2Dialect.class, majorVersion = 2, matchSubTypes = true, reason = "See https://github.com/h2database/h2database/issues/3338")
|
||||
public class FetchingTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
doInJPA(this::entityManagerFactory, entityManager -> {
|
||||
public void test(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
Department department = new Department();
|
||||
department.id = 1L;
|
||||
entityManager.persist(department);
|
||||
@ -72,7 +71,7 @@ public void test() {
|
||||
|
||||
});
|
||||
|
||||
doInJPA(this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
String username = "user1";
|
||||
String password = "3fabb4de8f1ee2e97d7793bab2db1116";
|
||||
//tag::fetching-strategies-no-fetching-example[]
|
||||
@ -90,7 +89,7 @@ public void test() {
|
||||
assertNotNull(employee);
|
||||
});
|
||||
|
||||
doInJPA(this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
String username = "user1";
|
||||
String password = "3fabb4de8f1ee2e97d7793bab2db1116";
|
||||
//tag::fetching-strategies-no-fetching-scalar-example[]
|
||||
@ -108,7 +107,7 @@ public void test() {
|
||||
assertEquals(Integer.valueOf(0), accessLevel);
|
||||
});
|
||||
|
||||
doInJPA(this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
String username = "user1";
|
||||
String password = "3fabb4de8f1ee2e97d7793bab2db1116";
|
||||
//tag::fetching-strategies-dynamic-fetching-jpql-example[]
|
||||
@ -127,7 +126,7 @@ public void test() {
|
||||
assertNotNull(employee);
|
||||
});
|
||||
|
||||
doInJPA(this::entityManagerFactory, entityManager -> {
|
||||
scope.inTransaction( entityManager -> {
|
||||
String username = "user1";
|
||||
String password = "3fabb4de8f1ee2e97d7793bab2db1116";
|
||||
//tag::fetching-strategies-dynamic-fetching-criteria-example[]
|
||||
@ -176,6 +175,12 @@ public static class Employee {
|
||||
read = "decrypt('AES', '00', pswd )",
|
||||
write = "encrypt('AES', '00', ?)"
|
||||
)
|
||||
// For H2 2.0.202+ one must use the varbinary DDL type
|
||||
// @Column(name = "pswd", columnDefinition = "varbinary")
|
||||
// @ColumnTransformer(
|
||||
// read = "trim(trailing u&'\\0000' from cast(decrypt('AES', '00', pswd ) as character varying))",
|
||||
// write = "encrypt('AES', '00', ?)"
|
||||
// )
|
||||
private String password;
|
||||
|
||||
private int accessLevel;
|
||||
|
@ -6,13 +6,6 @@
|
||||
*/
|
||||
package org.hibernate.orm.test.jpa.procedure;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Parameter;
|
||||
import jakarta.persistence.ParameterMode;
|
||||
import jakarta.persistence.StoredProcedureQuery;
|
||||
import jakarta.persistence.Table;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@ -20,13 +13,20 @@
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Parameter;
|
||||
import jakarta.persistence.ParameterMode;
|
||||
import jakarta.persistence.StoredProcedureQuery;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
@ -37,60 +37,35 @@
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@Jpa( annotatedClasses = H2StoreProcedureTest.MyEntity.class)
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
public class H2StoreProcedureTest extends BaseEntityManagerFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {MyEntity.class};
|
||||
public class H2StoreProcedureTest {
|
||||
|
||||
@BeforeAll
|
||||
public void setUp(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
entityManager.createNativeQuery( "CREATE ALIAS get_all_entities FOR \"" + H2StoreProcedureTest.class.getCanonicalName() + ".getAllEntities\";" )
|
||||
.executeUpdate();
|
||||
|
||||
entityManager.createNativeQuery( "CREATE ALIAS by_id FOR \"" + H2StoreProcedureTest.class.getCanonicalName() + ".entityById\";" )
|
||||
.executeUpdate();
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.id = 1;
|
||||
entity.name = "entity1";
|
||||
entityManager.persist( entity );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
final EntityManager entityManager = getOrCreateEntityManager();
|
||||
try {
|
||||
entityManager.getTransaction().begin();
|
||||
entityManager.createNativeQuery( "CREATE ALIAS get_all_entities FOR \"" + H2StoreProcedureTest.class.getCanonicalName() + ".getAllEntities\";" )
|
||||
.executeUpdate();
|
||||
|
||||
entityManager.createNativeQuery( "CREATE ALIAS by_id FOR \"" + H2StoreProcedureTest.class.getCanonicalName() + ".entityById\";" )
|
||||
.executeUpdate();
|
||||
MyEntity entity = new MyEntity();
|
||||
entity.id = 1;
|
||||
entity.name = "entity1";
|
||||
entityManager.persist( entity );
|
||||
|
||||
entityManager.getTransaction().commit();
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( entityManager.getTransaction().isActive() ) {
|
||||
entityManager.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
entityManager.close();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
final EntityManager entityManager = getOrCreateEntityManager();
|
||||
try {
|
||||
entityManager.getTransaction().begin();
|
||||
entityManager.createNativeQuery( "DROP ALIAS IF EXISTS get_all_entities" ).executeUpdate();
|
||||
entityManager.createNativeQuery( "DROP ALIAS IF EXISTS by_id" ).executeUpdate();
|
||||
entityManager.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( entityManager.getTransaction().isActive() ) {
|
||||
entityManager.getTransaction().rollback();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
finally {
|
||||
entityManager.close();
|
||||
}
|
||||
@AfterAll
|
||||
public void tearDown(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
entityManager.createNativeQuery( "DROP ALIAS IF EXISTS get_all_entities" ).executeUpdate();
|
||||
entityManager.createNativeQuery( "DROP ALIAS IF EXISTS by_id" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static ResultSet getAllEntities(Connection conn) throws SQLException {
|
||||
@ -102,50 +77,49 @@ public static ResultSet entityById(Connection conn, long id) throws SQLException
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreProcedureGetParameters() {
|
||||
final EntityManager entityManager = getOrCreateEntityManager();
|
||||
try {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "get_all_entities", MyEntity.class );
|
||||
final Set<Parameter<?>> parameters = query.getParameters();
|
||||
assertThat( parameters.size(), is( 0 ) );
|
||||
public void testStoreProcedureGetParameters(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery(
|
||||
"get_all_entities",
|
||||
MyEntity.class
|
||||
);
|
||||
final Set<Parameter<?>> parameters = query.getParameters();
|
||||
assertThat( parameters.size(), is( 0 ) );
|
||||
|
||||
final List resultList = query.getResultList();
|
||||
assertThat( resultList.size(), is( 1 ) );
|
||||
}
|
||||
finally {
|
||||
entityManager.close();
|
||||
}
|
||||
final List resultList = query.getResultList();
|
||||
assertThat( resultList.size(), is( 1 ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreProcedureGetParameterByPosition() {
|
||||
final EntityManager entityManager = getOrCreateEntityManager();
|
||||
try {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "by_Id", MyEntity.class );
|
||||
query.registerStoredProcedureParameter( 1, Long.class, ParameterMode.IN );
|
||||
public void testStoreProcedureGetParameterByPosition(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "by_Id", MyEntity.class );
|
||||
query.registerStoredProcedureParameter( 1, Long.class, ParameterMode.IN );
|
||||
|
||||
query.setParameter( 1, 1L );
|
||||
query.setParameter( 1, 1L );
|
||||
|
||||
final List resultList = query.getResultList();
|
||||
assertThat( resultList.size(), is( 1 ) );
|
||||
final List resultList = query.getResultList();
|
||||
assertThat( resultList.size(), is( 1 ) );
|
||||
|
||||
final Set<Parameter<?>> parameters = query.getParameters();
|
||||
assertThat( parameters.size(), is( 1 ) );
|
||||
final Set<Parameter<?>> parameters = query.getParameters();
|
||||
assertThat( parameters.size(), is( 1 ) );
|
||||
|
||||
final Parameter<?> parameter = query.getParameter( 1 );
|
||||
assertThat( parameter, not( nullValue() ) );
|
||||
final Parameter<?> parameter = query.getParameter( 1 );
|
||||
assertThat( parameter, not( nullValue() ) );
|
||||
|
||||
try {
|
||||
query.getParameter( 2 );
|
||||
fail( "IllegalArgumentException expected, parameter at position 2 does not exist" );
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
//expected
|
||||
}
|
||||
}
|
||||
finally {
|
||||
entityManager.close();
|
||||
}
|
||||
try {
|
||||
query.getParameter( 2 );
|
||||
fail( "IllegalArgumentException expected, parameter at position 2 does not exist" );
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
//expected
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Entity(name = "MyEntity")
|
||||
|
@ -9,7 +9,9 @@
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.DatabaseVersion;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
@ -56,7 +58,19 @@ public String getSetting() {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestDialect extends H2Dialect{
|
||||
public static class TestDialect extends H2Dialect {
|
||||
|
||||
public TestDialect(DialectResolutionInfo info) {
|
||||
super( info );
|
||||
}
|
||||
|
||||
public TestDialect() {
|
||||
}
|
||||
|
||||
public TestDialect(DatabaseVersion version) {
|
||||
super( version );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInExpressionCountLimit() {
|
||||
return 50;
|
||||
|
@ -19,7 +19,9 @@
|
||||
import org.hibernate.annotations.Formula;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.DatabaseVersion;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
@ -200,6 +202,19 @@ public static class ExtendedDialect extends H2Dialect {
|
||||
|
||||
public ExtendedDialect() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ExtendedDialect(DatabaseVersion version) {
|
||||
super( version );
|
||||
}
|
||||
|
||||
public ExtendedDialect(DialectResolutionInfo info) {
|
||||
super( info );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerDefaultKeywords() {
|
||||
super.registerDefaultKeywords();
|
||||
registerKeyword( "FLOAT" );
|
||||
registerKeyword( "INTEGER" );
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -41,6 +42,7 @@
|
||||
@DomainModel(annotatedClasses = Post.class)
|
||||
@SessionFactory
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
@SkipForDialect(dialectClass = H2Dialect.class, majorVersion = 2, reason = "Array support was changed to now be typed")
|
||||
public class StringArrayContributorTests {
|
||||
@Test
|
||||
public void simpleTest(SessionFactoryScope scope) {
|
||||
|
@ -35,6 +35,7 @@
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
@ -42,6 +43,7 @@
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-12292")
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
@SkipForDialect(dialectClass = H2Dialect.class, majorVersion = 2, reason = "Array support was changed to now be typed")
|
||||
@Jpa(
|
||||
annotatedClasses = QueryParametersValidationArrayTest.Event.class
|
||||
)
|
||||
|
@ -17,6 +17,8 @@
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
@ -30,6 +32,7 @@
|
||||
import org.hibernate.tool.schema.spi.SchemaManagementTool;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
@ -88,6 +91,9 @@ public void testAddingMultipleExtraPhysicalTableTypes() throws Exception {
|
||||
@Test
|
||||
public void testExtraPhysicalTableTypesPropertyEmptyStringValue() throws Exception {
|
||||
buildMetadata( " " );
|
||||
Dialect dialect = metadata.getDatabase().getDialect();
|
||||
// As of 2.0.202 H2 reports tables as BASE TABLE so we add the type through the dialect
|
||||
Assume.assumeFalse( dialect instanceof H2Dialect && dialect.getVersion().isSameOrAfter( 2 ) );
|
||||
DdlTransactionIsolator ddlTransactionIsolator = buildDdlTransactionIsolator();
|
||||
try {
|
||||
InformationExtractorJdbcDatabaseMetaDataImplTest informationExtractor = buildInformationExtractorJdbcDatabaseMetaDataImplTest(
|
||||
@ -102,8 +108,11 @@ public void testExtraPhysicalTableTypesPropertyEmptyStringValue() throws Excepti
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoExtraPhysicalTabeTypesProperty() throws Exception {
|
||||
public void testNoExtraPhysicalTableTypesProperty() throws Exception {
|
||||
buildMetadata( null );
|
||||
Dialect dialect = metadata.getDatabase().getDialect();
|
||||
// As of 2.0.202 H2 reports tables as BASE TABLE so we add the type through the dialect
|
||||
Assume.assumeFalse( dialect instanceof H2Dialect && dialect.getVersion().isSameOrAfter( 2 ) );
|
||||
DdlTransactionIsolator ddlTransactionIsolator = buildDdlTransactionIsolator();
|
||||
try {
|
||||
InformationExtractorJdbcDatabaseMetaDataImplTest informationExtractor = buildInformationExtractorJdbcDatabaseMetaDataImplTest(
|
||||
|
@ -245,7 +245,19 @@ public void testMismatchColumnType() throws Exception {
|
||||
Assert.fail( "SchemaManagementException expected" );
|
||||
}
|
||||
catch (SchemaManagementException e) {
|
||||
assertEquals("Schema-validation: wrong column type encountered in column [name] in table [SomeSchema.ColumnEntity]; found [varchar (Types#VARCHAR)], but expecting [integer (Types#INTEGER)]", e.getMessage());
|
||||
if ( metadata.getDatabase().getDialect().getVersion().isSameOrAfter( 2 ) ) {
|
||||
// Reports "character varying" since 2.0
|
||||
assertEquals(
|
||||
"Schema-validation: wrong column type encountered in column [name] in table [SomeSchema.ColumnEntity]; found [character (Types#VARCHAR)], but expecting [integer (Types#INTEGER)]",
|
||||
e.getMessage()
|
||||
);
|
||||
}
|
||||
else {
|
||||
assertEquals(
|
||||
"Schema-validation: wrong column type encountered in column [name] in table [SomeSchema.ColumnEntity]; found [varchar (Types#VARCHAR)], but expecting [integer (Types#INTEGER)]",
|
||||
e.getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
@ -25,6 +25,7 @@
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import org.hibernate.dialect.AbstractHANADialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.dialect.HSQLDialect;
|
||||
import org.hibernate.dialect.MariaDBDialect;
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
@ -234,6 +235,7 @@ protected Object getActualJdbcValue(ResultSet resultSet, int columnIndex) throws
|
||||
+ " Since java.sql.Time holds the whole timestamp, not just the time,"
|
||||
+ " its equals() method ends up returning false in this test.")
|
||||
@SkipForDialect(value = HSQLDialect.class, comment = "Timezone issue?")
|
||||
@SkipForDialect(value = H2Dialect.class, comment = "As of version 2.0.202 this seems to be a problem")
|
||||
public void writeThenNativeRead() {
|
||||
super.writeThenNativeRead();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user