HHH-15406 Tests annotated with org.hibernate.testing.RequiresDialect having as value a deprecated dialect are not executed

This commit is contained in:
Andrea Boriero 2022-07-20 13:16:41 +02:00 committed by Andrea Boriero
parent 38589b5e7b
commit 0f599da6c4
17 changed files with 562 additions and 528 deletions

View File

@ -15,32 +15,30 @@ import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType; import jakarta.persistence.InheritanceType;
import org.hibernate.annotations.DiscriminatorFormula; import org.hibernate.annotations.DiscriminatorFormula;
import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.junit.Assert; import org.hibernate.testing.orm.junit.Jpa;
import org.junit.Test; import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
public class SingleTableDiscriminatorFormulaTest extends BaseEntityManagerFunctionalTestCase { @Jpa(
annotatedClasses = {
@Override SingleTableDiscriminatorFormulaTest.DebitAccount.class,
protected Class<?>[] getAnnotatedClasses() { SingleTableDiscriminatorFormulaTest.CreditAccount.class,
return new Class<?>[] {
DebitAccount.class,
CreditAccount.class,
};
} }
)
public class SingleTableDiscriminatorFormulaTest {
@Test @Test
@RequiresDialect({PostgreSQL81Dialect.class}) @RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 1)
public void test() { public void test(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction(entityManager -> {
DebitAccount debitAccount = new DebitAccount("123-debit"); DebitAccount debitAccount = new DebitAccount("123-debit");
debitAccount.setId(1L); debitAccount.setId(1L);
debitAccount.setOwner("John Doe"); debitAccount.setOwner("John Doe");
@ -59,10 +57,10 @@ public class SingleTableDiscriminatorFormulaTest extends BaseEntityManagerFuncti
entityManager.persist(creditAccount); entityManager.persist(creditAccount);
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction(entityManager -> {
List<Account> accounts = List<Account> accounts =
entityManager.createQuery("select a from Account a").getResultList(); entityManager.createQuery("select a from Account a").getResultList();
Assert.assertEquals(2, accounts.size()); assertEquals(2, accounts.size());
}); });
} }

View File

@ -23,38 +23,51 @@ import jakarta.persistence.PessimisticLockScope;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.junit.Test; import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
public class ExplicitLockingTest extends BaseEntityManagerFunctionalTestCase { @Jpa(
annotatedClasses = {
ExplicitLockingTest.Person.class,
ExplicitLockingTest.Phone.class,
}
)
public class ExplicitLockingTest {
@Override protected final Logger log = Logger.getLogger( getClass() );
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { @AfterEach
Person.class, public void tearDown(EntityManagerFactoryScope scope) {
Phone.class, scope.inTransaction(
}; entityManager ->
entityManager.createQuery( "delete from Person" ).executeUpdate()
);
} }
@Test @Test
public void testJPALockTimeout() { public void testJPALockTimeout(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { Person p = scope.fromTransaction( entityManager -> {
Person person = new Person("John Doe"); Person person = new Person("John Doe");
entityManager.persist(person); entityManager.persist(person);
return person;
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
log.info("testJPALockTimeout"); log.info("testJPALockTimeout");
Long id = 1L; Long id = p.getId();
//tag::locking-jpa-query-hints-timeout-example[] //tag::locking-jpa-query-hints-timeout-example[]
entityManager.find( entityManager.find(
Person.class, id, LockModeType.PESSIMISTIC_WRITE, Person.class, id, LockModeType.PESSIMISTIC_WRITE,
@ -65,8 +78,8 @@ public class ExplicitLockingTest extends BaseEntityManagerFunctionalTestCase {
} }
@Test @Test
public void testJPALockScope() { public void testJPALockScope(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { Person p = scope.fromTransaction( entityManager -> {
Person person = new Person("John Doe"); Person person = new Person("John Doe");
entityManager.persist(person); entityManager.persist(person);
Phone home = new Phone("123-456-7890"); Phone home = new Phone("123-456-7890");
@ -74,10 +87,11 @@ public class ExplicitLockingTest extends BaseEntityManagerFunctionalTestCase {
person.getPhones().add(home); person.getPhones().add(home);
person.getPhones().add(office); person.getPhones().add(office);
entityManager.persist(person); entityManager.persist(person);
return person;
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
log.info("testJPALockScope"); log.info("testJPALockScope");
Long id = 1L; Long id = p.getId();
//tag::locking-jpa-query-hints-scope-example[] //tag::locking-jpa-query-hints-scope-example[]
Person person = entityManager.find( Person person = entityManager.find(
Person.class, id, LockModeType.PESSIMISTIC_WRITE, Person.class, id, LockModeType.PESSIMISTIC_WRITE,
@ -91,8 +105,8 @@ public class ExplicitLockingTest extends BaseEntityManagerFunctionalTestCase {
} }
@Test @Test
public void testBuildLockRequest() { public void testBuildLockRequest(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { Person p = scope.fromTransaction( entityManager -> {
log.info("testBuildLockRequest"); log.info("testBuildLockRequest");
Person person = new Person("John Doe"); Person person = new Person("John Doe");
Phone home = new Phone("123-456-7890"); Phone home = new Phone("123-456-7890");
@ -101,9 +115,10 @@ public class ExplicitLockingTest extends BaseEntityManagerFunctionalTestCase {
person.getPhones().add(office); person.getPhones().add(office);
entityManager.persist(person); entityManager.persist(person);
entityManager.flush(); entityManager.flush();
return person;
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Long id = 1L; Long id = p.getId();
//tag::locking-buildLockRequest-example[] //tag::locking-buildLockRequest-example[]
Person person = entityManager.find(Person.class, id); Person person = entityManager.find(Person.class, id);
Session session = entityManager.unwrap(Session.class); Session session = entityManager.unwrap(Session.class);
@ -115,8 +130,8 @@ public class ExplicitLockingTest extends BaseEntityManagerFunctionalTestCase {
//end::locking-buildLockRequest-example[] //end::locking-buildLockRequest-example[]
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Long id = 1L; Long id = p.getId();
//tag::locking-buildLockRequest-scope-example[] //tag::locking-buildLockRequest-scope-example[]
Person person = entityManager.find(Person.class, id); Person person = entityManager.find(Person.class, id);
Session session = entityManager.unwrap(Session.class); Session session = entityManager.unwrap(Session.class);
@ -132,9 +147,9 @@ public class ExplicitLockingTest extends BaseEntityManagerFunctionalTestCase {
} }
@Test @Test
@RequiresDialect(Oracle8iDialect.class) @RequiresDialect(value = OracleDialect.class, majorVersion = 8)
public void testFollowOnLocking() { public void testFollowOnLocking(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
log.info("testBuildLockRequest"); log.info("testBuildLockRequest");
Person person1 = new Person("John Doe"); Person person1 = new Person("John Doe");
Person person2 = new Person("Mrs. John Doe"); Person person2 = new Person("Mrs. John Doe");
@ -144,7 +159,7 @@ public class ExplicitLockingTest extends BaseEntityManagerFunctionalTestCase {
entityManager.flush(); entityManager.flush();
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::locking-follow-on-example[] //tag::locking-follow-on-example[]
List<Person> persons = entityManager.createQuery( List<Person> persons = entityManager.createQuery(
"select DISTINCT p from Person p", Person.class) "select DISTINCT p from Person p", Person.class)
@ -153,7 +168,7 @@ public class ExplicitLockingTest extends BaseEntityManagerFunctionalTestCase {
//end::locking-follow-on-example[] //end::locking-follow-on-example[]
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::locking-follow-on-secondary-query-example[] //tag::locking-follow-on-secondary-query-example[]
List<Person> persons = entityManager.createQuery( List<Person> persons = entityManager.createQuery(
"select DISTINCT p from Person p", Person.class) "select DISTINCT p from Person p", Person.class)
@ -167,7 +182,7 @@ public class ExplicitLockingTest extends BaseEntityManagerFunctionalTestCase {
//end::locking-follow-on-secondary-query-example[] //end::locking-follow-on-secondary-query-example[]
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::locking-follow-on-explicit-example[] //tag::locking-follow-on-explicit-example[]
List<Person> persons = entityManager.createQuery( List<Person> persons = entityManager.createQuery(
"select p from Person p", Person.class) "select p from Person p", Person.class)

View File

@ -13,30 +13,26 @@ import jakarta.persistence.Id;
import org.hibernate.annotations.Generated; import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime; import org.hibernate.annotations.GenerationTime;
import org.hibernate.dialect.SQLServer2005Dialect; import org.hibernate.dialect.SQLServer2005Dialect;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.junit.Test; import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialect(SQLServer2005Dialect.class) @RequiresDialect(value = SQLServer2005Dialect.class, majorVersion = 9)
public class GeneratedTest extends BaseEntityManagerFunctionalTestCase { @Jpa(
annotatedClasses = GeneratedTest.Person.class
@Override )
protected Class<?>[] getAnnotatedClasses() { public class GeneratedTest {
return new Class<?>[] {
Person.class
};
}
@Test @Test
public void test() { public void test(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::mapping-generated-Generated-persist-example[] //tag::mapping-generated-Generated-persist-example[]
Person person = new Person(); Person person = new Person();
person.setId(1L); person.setId(1L);
@ -54,7 +50,7 @@ public class GeneratedTest extends BaseEntityManagerFunctionalTestCase {
assertEquals("John Flávio André Frederico Rúben Artur Doe", person.getFullName()); assertEquals("John Flávio André Frederico Rúben Artur Doe", person.getFullName());
//end::mapping-generated-Generated-persist-example[] //end::mapping-generated-Generated-persist-example[]
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::mapping-generated-Generated-update-example[] //tag::mapping-generated-Generated-update-example[]
Person person = entityManager.find(Person.class, 1L); Person person = entityManager.find(Person.class, 1L);
person.setLastName("Doe Jr"); person.setLastName("Doe Jr");

View File

@ -11,37 +11,32 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import org.hibernate.annotations.RowId; import org.hibernate.annotations.RowId;
import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.junit.Test; import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialect;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import org.junit.jupiter.api.Test;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialect(Oracle8iDialect.class) @RequiresDialect(value = OracleDialect.class, majorVersion = 8)
public class RowIdTest extends BaseEntityManagerFunctionalTestCase { @Jpa(
annotatedClasses = RowIdTest.Product.class
@Override )
protected Class<?>[] getAnnotatedClasses() { public class RowIdTest {
return new Class<?>[] {
Product.class
};
}
@Test @Test
public void test() { public void test(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Product product = new Product(); Product product = new Product();
product.setId(1L); product.setId(1L);
product.setName("Mobile phone"); product.setName("Mobile phone");
product.setNumber("123-456-7890"); product.setNumber("123-456-7890");
entityManager.persist(product); entityManager.persist(product);
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::identifiers-rowid-example[] //tag::identifiers-rowid-example[]
Product product = entityManager.find(Product.class, 1L); Product product = entityManager.find(Product.class, 1L);

View File

@ -9,8 +9,11 @@ package org.hibernate.userguide.schema;
import java.sql.Blob; import java.sql.Blob;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.hibernate.annotations.LazyGroup;
import org.hibernate.annotations.NaturalId;
import jakarta.persistence.Basic; import jakarta.persistence.Basic;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
@ -19,61 +22,7 @@ import jakarta.persistence.Lob;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import org.hibernate.annotations.LazyGroup; public abstract class BaseSchemaGeneratorTest {
import org.hibernate.annotations.NaturalId;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.junit.Test;
/**
* @author Vlad Mihalcea
*/
public class SchemaGenerationTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Person.class,
Book.class,
Customer.class
};
}
@Override
protected Map buildSettings() {
Map settings = super.buildSettings();
if (getDialect().getClass().equals(H2Dialect.class)) {
settings.put(
AvailableSettings.HBM2DDL_IMPORT_FILES,
"schema-generation.sql"
);
settings.put(AvailableSettings.HBM2DDL_AUTO, "update");
}
return settings;
}
@Override
protected String[] getMappings() {
if (PostgreSQL81Dialect.class.isAssignableFrom(getDialect().getClass())) {
return new String[] { "org/hibernate/userguide/schema/SchemaGenerationTest.hbm.xml" };
}
return super.getMappings();
}
@Test
@RequiresDialect(H2Dialect.class)
public void testH2() {
}
@Test
@RequiresDialect(PostgreSQL81Dialect.class)
public void testPostgres() {
}
//tag::schema-generation-domain-model-example[] //tag::schema-generation-domain-model-example[]
@Entity(name = "Customer") @Entity(name = "Customer")
public class Customer { public class Customer {

View File

@ -0,0 +1,38 @@
/*
* 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.userguide.schema;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
/**
* @author Vlad Mihalcea
*/
@RequiresDialect( H2Dialect.class )
@Jpa(
annotatedClasses = {
BaseSchemaGeneratorTest.Person.class,
BaseSchemaGeneratorTest.Book.class,
BaseSchemaGeneratorTest.Customer.class
},
integrationSettings = {
@Setting( name = AvailableSettings.HBM2DDL_IMPORT_FILES, value = "schema-generation.sql"),
@Setting( name = AvailableSettings.HBM2DDL_AUTO, value = "update")
}
)
public class H2SchemaGenerationTest extends BaseSchemaGeneratorTest {
@Test
public void testH2() {
}
}

View File

@ -0,0 +1,34 @@
/*
* 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.userguide.schema;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test;
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8)
@Jpa(
annotatedClasses = {
BaseSchemaGeneratorTest.Person.class,
BaseSchemaGeneratorTest.Book.class,
BaseSchemaGeneratorTest.Customer.class
},
xmlMappings = "org/hibernate/userguide/schema/SchemaGenerationTest.hbm.xml",
integrationSettings = {
@Setting(name = AvailableSettings.HBM2DDL_IMPORT_FILES, value = "schema-generation.sql"),
@Setting(name = AvailableSettings.HBM2DDL_AUTO, value = "update")
}
)
public class PostgreSQLSchemaGenerationTest extends BaseSchemaGeneratorTest {
@Test
public void testPostgres() {
}
}

View File

@ -8,52 +8,58 @@ import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import jakarta.persistence.ParameterMode;
import jakarta.persistence.StoredProcedureQuery;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.dialect.MySQLDialect;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; import org.hibernate.dialect.TiDBDialect;
import org.hibernate.procedure.ProcedureCall; import org.hibernate.procedure.ProcedureCall;
import org.hibernate.query.procedure.ProcedureParameter; import org.hibernate.query.procedure.ProcedureParameter;
import org.hibernate.result.Output; import org.hibernate.result.Output;
import org.hibernate.result.ResultSetOutput; import org.hibernate.result.ResultSetOutput;
import org.hibernate.userguide.model.Account;
import org.hibernate.userguide.model.AddressType; import org.hibernate.userguide.model.AddressType;
import org.hibernate.userguide.model.Call; import org.hibernate.userguide.model.Call;
import org.hibernate.userguide.model.Partner; import org.hibernate.userguide.model.Partner;
import org.hibernate.userguide.model.Payment;
import org.hibernate.userguide.model.Person; import org.hibernate.userguide.model.Person;
import org.hibernate.userguide.model.Phone; import org.hibernate.userguide.model.Phone;
import org.hibernate.userguide.model.PhoneType; import org.hibernate.userguide.model.PhoneType;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.junit.After; import org.hibernate.testing.orm.junit.Jpa;
import org.junit.Before; import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.Test; import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import jakarta.persistence.ParameterMode;
import static org.junit.Assert.assertEquals; import jakarta.persistence.StoredProcedureQuery;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialect(MySQL5Dialect.class) @RequiresDialect(value = MySQLDialect.class, majorVersion = 5)
public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCase { @SkipForDialect(dialectClass = TiDBDialect.class, reason = "TiDB doesn't support stored procedures")
@Jpa(
@Override annotatedClasses = {
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Person.class, Person.class,
Partner.class, Partner.class,
Phone.class, Phone.class,
Call.class, Call.class,
}; Payment.class,
Account.class
} }
)
public class MySQLStoredProcedureTest {
@Before @BeforeAll
public void init() { public void init(EntityManagerFactoryScope scope) {
destroy(); destroy( scope );
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Session session = entityManager.unwrap( Session.class ); Session session = entityManager.unwrap( Session.class );
session.doWork( connection -> { session.doWork( connection -> {
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
@ -98,7 +104,7 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
} }
} ); } );
} ); } );
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Person person1 = new Person( "John Doe" ); Person person1 = new Person( "John Doe" );
person1.setNickName( "JD" ); person1.setNickName( "JD" );
person1.setAddress( "Earth" ); person1.setAddress( "Earth" );
@ -122,9 +128,9 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
} ); } );
} }
@After @AfterAll
public void destroy() { public void destroy(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Session session = entityManager.unwrap( Session.class ); Session session = entityManager.unwrap( Session.class );
session.doWork( connection -> { session.doWork( connection -> {
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
@ -134,7 +140,7 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
} }
} ); } );
} ); } );
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Session session = entityManager.unwrap( Session.class ); Session session = entityManager.unwrap( Session.class );
session.doWork( connection -> { session.doWork( connection -> {
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
@ -144,7 +150,7 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
} }
} ); } );
} ); } );
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Session session = entityManager.unwrap( Session.class ); Session session = entityManager.unwrap( Session.class );
session.doWork( connection -> { session.doWork( connection -> {
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
@ -157,8 +163,8 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
} }
@Test @Test
public void testStoredProcedureOutParameter() { public void testStoredProcedureOutParameter(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::sql-jpa-call-sp-out-mysql-example[] //tag::sql-jpa-call-sp-out-mysql-example[]
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_count_phones" ); StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_count_phones" );
query.registerStoredProcedureParameter( "personId", Long.class, ParameterMode.IN ); query.registerStoredProcedureParameter( "personId", Long.class, ParameterMode.IN );
@ -169,13 +175,13 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
query.execute(); query.execute();
Long phoneCount = (Long) query.getOutputParameterValue( "phoneCount" ); Long phoneCount = (Long) query.getOutputParameterValue( "phoneCount" );
//end::sql-jpa-call-sp-out-mysql-example[] //end::sql-jpa-call-sp-out-mysql-example[]
assertEquals(Long.valueOf(2), phoneCount); assertEquals( 2l, phoneCount );
} ); } );
} }
@Test @Test
public void testHibernateProcedureCallOutParameter() { public void testHibernateProcedureCallOutParameter(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::sql-hibernate-call-sp-out-mysql-example[] //tag::sql-hibernate-call-sp-out-mysql-example[]
Session session = entityManager.unwrap( Session.class ); Session session = entityManager.unwrap( Session.class );
@ -191,9 +197,9 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
} }
@Test @Test
public void testStoredProcedureRefCursor() { public void testStoredProcedureRefCursor(EntityManagerFactoryScope scope) {
try { try {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_phones" ); StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_phones" );
query.registerStoredProcedureParameter( 1, void.class, ParameterMode.REF_CURSOR ); query.registerStoredProcedureParameter( 1, void.class, ParameterMode.REF_CURSOR );
query.registerStoredProcedureParameter( 2, Long.class, ParameterMode.IN ); query.registerStoredProcedureParameter( 2, Long.class, ParameterMode.IN );
@ -203,14 +209,17 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
List<Object[]> personComments = query.getResultList(); List<Object[]> personComments = query.getResultList();
assertEquals( 2, personComments.size() ); assertEquals( 2, personComments.size() );
} ); } );
} catch (Exception e) { }
assertTrue(Pattern.compile("Dialect .*? not known to support REF_CURSOR parameters").matcher(e.getCause().getMessage()).matches()); catch (Exception e) {
assertTrue( Pattern.compile( "Dialect .*? not known to support REF_CURSOR parameters" )
.matcher( e.getCause().getMessage() )
.matches() );
} }
} }
@Test @Test
public void testStoredProcedureReturnValue() { public void testStoredProcedureReturnValue(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::sql-jpa-call-sp-no-out-mysql-example[] //tag::sql-jpa-call-sp-no-out-mysql-example[]
StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_phones" ); StoredProcedureQuery query = entityManager.createStoredProcedureQuery( "sp_phones" );
query.registerStoredProcedureParameter( 1, Long.class, ParameterMode.IN ); query.registerStoredProcedureParameter( 1, Long.class, ParameterMode.IN );
@ -224,8 +233,8 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
} }
@Test @Test
public void testHibernateProcedureCallReturnValueParameter() { public void testHibernateProcedureCallReturnValueParameter(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::sql-hibernate-call-sp-no-out-mysql-example[] //tag::sql-hibernate-call-sp-no-out-mysql-example[]
Session session = entityManager.unwrap( Session.class ); Session session = entityManager.unwrap( Session.class );
@ -242,8 +251,8 @@ public class MySQLStoredProcedureTest extends BaseEntityManagerFunctionalTestCas
} }
@Test @Test
public void testFunctionWithJDBC() { public void testFunctionWithJDBC(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::sql-call-function-mysql-example[] //tag::sql-call-function-mysql-example[]
final AtomicReference<Integer> phoneCount = new AtomicReference<>(); final AtomicReference<Integer> phoneCount = new AtomicReference<>();
Session session = entityManager.unwrap( Session.class ); Session session = entityManager.unwrap( Session.class );

View File

@ -7,44 +7,42 @@
package org.hibernate.userguide.sql; package org.hibernate.userguide.sql;
import java.sql.Statement; import java.sql.Statement;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.NamedNativeQueries;
import jakarta.persistence.NamedNativeQuery;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.annotations.Loader; import org.hibernate.annotations.Loader;
import org.hibernate.annotations.ResultCheckStyle; import org.hibernate.annotations.ResultCheckStyle;
import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLInsert; import org.hibernate.annotations.SQLInsert;
import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.junit.Before; import org.hibernate.testing.orm.junit.Jpa;
import org.junit.Test; import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.NamedNativeQueries;
import jakarta.persistence.NamedNativeQuery;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialect(Oracle8iDialect.class) @RequiresDialect(value = OracleDialect.class, majorVersion = 8)
public class OracleCustomSQLWithStoredProcedureTest extends BaseEntityManagerFunctionalTestCase { @Jpa(
annotatedClasses = OracleCustomSQLWithStoredProcedureTest.Person.class
)
public class OracleCustomSQLWithStoredProcedureTest {
@Override @BeforeAll
protected Class<?>[] getAnnotatedClasses() { public void init(EntityManagerFactoryScope scope) {
return new Class<?>[] { scope.inTransaction( entityManager -> {
Person.class
};
}
@Before
public void init() {
doInJPA(this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap( Session.class ); Session session = entityManager.unwrap( Session.class );
session.doWork( connection -> { session.doWork( connection -> {
try (Statement statement = connection.createStatement();) { try (Statement statement = connection.createStatement();) {
@ -57,30 +55,31 @@ public class OracleCustomSQLWithStoredProcedureTest extends BaseEntityManagerFun
"BEGIN " + "BEGIN " +
" UPDATE person SET valid = 0 WHERE id = personId; " + " UPDATE person SET valid = 0 WHERE id = personId; " +
"END;" "END;"
);} );
}
//end::sql-sp-soft-delete-example[] //end::sql-sp-soft-delete-example[]
} ); } );
} ); } );
} }
@Test @Test
public void test_sql_custom_crud() { public void test_sql_custom_crud(EntityManagerFactoryScope scope) {
Person _person = doInJPA(this::entityManagerFactory, entityManager -> { Person _person = scope.fromTransaction( entityManager -> {
Person person = new Person(); Person person = new Person();
person.setName( "John Doe" ); person.setName( "John Doe" );
entityManager.persist( person ); entityManager.persist( person );
return person; return person;
} ); } );
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Long postId = _person.getId(); Long postId = _person.getId();
Person person = entityManager.find( Person.class, postId ); Person person = entityManager.find( Person.class, postId );
assertNotNull( person ); assertNotNull( person );
entityManager.remove( person ); entityManager.remove( person );
} ); } );
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Long postId = _person.getId(); Long postId = _person.getId();
Person person = entityManager.find( Person.class, postId ); Person person = entityManager.find( Person.class, postId );
assertNull( person ); assertNull( person );

View File

@ -3,55 +3,57 @@ package org.hibernate.userguide.sql;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List; import java.util.List;
import jakarta.persistence.ParameterMode;
import jakarta.persistence.StoredProcedureQuery;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.procedure.ProcedureCall; import org.hibernate.procedure.ProcedureCall;
import org.hibernate.query.procedure.ProcedureParameter; import org.hibernate.query.procedure.ProcedureParameter;
import org.hibernate.result.Output; import org.hibernate.result.Output;
import org.hibernate.result.ResultSetOutput; import org.hibernate.result.ResultSetOutput;
import org.hibernate.userguide.model.Account;
import org.hibernate.userguide.model.AddressType; import org.hibernate.userguide.model.AddressType;
import org.hibernate.userguide.model.Call; import org.hibernate.userguide.model.Call;
import org.hibernate.userguide.model.Partner; import org.hibernate.userguide.model.Partner;
import org.hibernate.userguide.model.Payment;
import org.hibernate.userguide.model.Person; import org.hibernate.userguide.model.Person;
import org.hibernate.userguide.model.Phone; import org.hibernate.userguide.model.Phone;
import org.hibernate.userguide.model.PhoneType; import org.hibernate.userguide.model.PhoneType;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.junit.After; import org.hibernate.testing.orm.junit.Jpa;
import org.junit.Before; import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.Test; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import jakarta.persistence.ParameterMode;
import jakarta.persistence.StoredProcedureQuery;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialect(Oracle8iDialect.class) @RequiresDialect(value = OracleDialect.class, majorVersion = 8)
public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCase { @Jpa(
annotatedClasses = {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Person.class, Person.class,
Partner.class, Partner.class,
Phone.class, Phone.class,
Call.class, Call.class,
}; Payment.class,
Account.class
} }
)
public class OracleStoredProcedureTest {
@Before @BeforeAll
public void init() { public void init(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Session session = entityManager.unwrap(Session.class); Session session = entityManager.unwrap(Session.class);
session.doWork(connection -> { session.doWork(connection -> {
try(Statement statement = connection.createStatement()) { try(Statement statement = connection.createStatement()) {
@ -96,7 +98,7 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa
} }
}); });
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Person person1 = new Person("John Doe"); Person person1 = new Person("John Doe");
person1.setNickName("JD"); person1.setNickName("JD");
person1.setAddress("Earth"); person1.setAddress("Earth");
@ -120,9 +122,9 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa
}); });
} }
@After @AfterAll
public void destroy() { public void destroy(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Session session = entityManager.unwrap(Session.class); Session session = entityManager.unwrap(Session.class);
session.doWork(connection -> { session.doWork(connection -> {
try(Statement statement = connection.createStatement()) { try(Statement statement = connection.createStatement()) {
@ -132,7 +134,7 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa
} }
}); });
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Session session = entityManager.unwrap(Session.class); Session session = entityManager.unwrap(Session.class);
session.doWork(connection -> { session.doWork(connection -> {
try(Statement statement = connection.createStatement()) { try(Statement statement = connection.createStatement()) {
@ -142,7 +144,7 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa
} }
}); });
}); });
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
Session session = entityManager.unwrap(Session.class); Session session = entityManager.unwrap(Session.class);
session.doWork(connection -> { session.doWork(connection -> {
try(Statement statement = connection.createStatement()) { try(Statement statement = connection.createStatement()) {
@ -155,8 +157,8 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa
} }
@Test @Test
public void testStoredProcedureOutParameter() { public void testStoredProcedureOutParameter(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_count_phones"); StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_count_phones");
query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN); query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
query.registerStoredProcedureParameter(2, Long.class, ParameterMode.OUT); query.registerStoredProcedureParameter(2, Long.class, ParameterMode.OUT);
@ -165,13 +167,13 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa
query.execute(); query.execute();
Long phoneCount = (Long) query.getOutputParameterValue(2); Long phoneCount = (Long) query.getOutputParameterValue(2);
assertEquals(Long.valueOf(2), phoneCount); assertEquals(2l, phoneCount);
}); });
} }
@Test @Test
public void testStoredProcedureRefCursor() { public void testStoredProcedureRefCursor(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::sql-jpa-call-sp-ref-cursor-oracle-example[] //tag::sql-jpa-call-sp-ref-cursor-oracle-example[]
StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_person_phones"); StoredProcedureQuery query = entityManager.createStoredProcedureQuery("sp_person_phones");
query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN); query.registerStoredProcedureParameter(1, Long.class, ParameterMode.IN);
@ -186,8 +188,8 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa
} }
@Test @Test
public void testStoredProcedureRefCursorUsingNamedQuery() { public void testStoredProcedureRefCursorUsingNamedQuery(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::sql-jpa-call-sp-ref-cursor-oracle-named-query-example[] //tag::sql-jpa-call-sp-ref-cursor-oracle-named-query-example[]
List<Object[]> postComments = entityManager List<Object[]> postComments = entityManager
.createNamedStoredProcedureQuery("sp_person_phones") .createNamedStoredProcedureQuery("sp_person_phones")
@ -200,8 +202,8 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa
} }
@Test @Test
public void testHibernateProcedureCallRefCursor() { public void testHibernateProcedureCallRefCursor(EntityManagerFactoryScope scope) {
doInJPA(this::entityManagerFactory, entityManager -> { scope.inTransaction( entityManager -> {
//tag::sql-hibernate-call-sp-ref-cursor-oracle-example[] //tag::sql-hibernate-call-sp-ref-cursor-oracle-example[]
Session session = entityManager.unwrap(Session.class); Session session = entityManager.unwrap(Session.class);
@ -218,9 +220,8 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa
} }
@Test @Test
public void testStoredProcedureReturnValue() { public void testStoredProcedureReturnValue(EntityManagerFactoryScope scope) {
try { scope.inTransaction( entityManager -> {
doInJPA(this::entityManagerFactory, entityManager -> {
BigDecimal phoneCount = (BigDecimal) entityManager BigDecimal phoneCount = (BigDecimal) entityManager
.createNativeQuery( "SELECT fn_count_phones(:personId) FROM DUAL" ) .createNativeQuery( "SELECT fn_count_phones(:personId) FROM DUAL" )
.setParameter( "personId", 1 ) .setParameter( "personId", 1 )
@ -228,8 +229,4 @@ public class OracleStoredProcedureTest extends BaseEntityManagerFunctionalTestCa
assertEquals( BigDecimal.valueOf( 2 ), phoneCount ); assertEquals( BigDecimal.valueOf( 2 ), phoneCount );
} ); } );
} }
catch (Exception e) {
e.printStackTrace();
}
}
} }

View File

@ -8,29 +8,34 @@ package org.hibernate.test.c3p0;
import java.sql.Statement; import java.sql.Statement;
import org.hibernate.dialect.SQLServer2005Dialect; import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.orm.junit.DomainModel;
import org.junit.Test; import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNotNull;
/** /**
* Tests that checks the JDBC 4.2 compatibility of c3p0 * Tests that checks the JDBC 4.2 compatibility of c3p0
* *
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@RequiresDialect(SQLServer2005Dialect.class) @RequiresDialect(value = SQLServerDialect.class, majorVersion = 9)
public class JdbcCompatibilityTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = { IrrelevantEntity.class }
)
@SessionFactory
public class JdbcCompatibilityTest {
@Test @Test
@TestForIssue(jiraKey = "HHH-11308") @TestForIssue(jiraKey = "HHH-11308")
public void testJdbc41() { public void testJdbc41(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
session.doWork( connection -> { session.doWork( connection -> {
//Connection#getSchema was added in Java 1.7 //Connection#getSchema was added in Java 1.7
String schema = connection.getSchema(); String schema = connection.getSchema();
@ -41,8 +46,8 @@ public class JdbcCompatibilityTest extends BaseCoreFunctionalTestCase {
@Test @Test
@TestForIssue(jiraKey = "HHH-11308") @TestForIssue(jiraKey = "HHH-11308")
public void testJdbc42() { public void testJdbc42(SessionFactoryScope scope) {
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
for ( int i = 0; i < 5; i++ ) { for ( int i = 0; i < 5; i++ ) {
IrrelevantEntity entity = new IrrelevantEntity(); IrrelevantEntity entity = new IrrelevantEntity();
entity.setName( getClass().getName() ); entity.setName( getClass().getName() );
@ -58,8 +63,4 @@ public class JdbcCompatibilityTest extends BaseCoreFunctionalTestCase {
} ); } );
} }
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[]{ IrrelevantEntity.class };
}
} }

View File

@ -20,7 +20,6 @@ import jakarta.persistence.StoredProcedureParameter;
import jakarta.persistence.StoredProcedureQuery; import jakarta.persistence.StoredProcedureQuery;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.dialect.OracleDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;

View File

@ -20,7 +20,6 @@ import jakarta.persistence.StoredProcedureParameter;
import jakarta.persistence.StoredProcedureQuery; import jakarta.persistence.StoredProcedureQuery;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.dialect.OracleDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;

View File

@ -20,6 +20,7 @@ import java.util.regex.Pattern;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.dialect.MariaDBDialect; import org.hibernate.dialect.MariaDBDialect;
import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.TiDBDialect;
import org.hibernate.procedure.ProcedureCall; import org.hibernate.procedure.ProcedureCall;
import org.hibernate.query.procedure.ProcedureParameter; import org.hibernate.query.procedure.ProcedureParameter;
import org.hibernate.result.Output; import org.hibernate.result.Output;
@ -30,6 +31,7 @@ import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa; import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialect; import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -48,6 +50,7 @@ import static org.junit.jupiter.api.Assertions.fail;
*/ */
@RequiresDialect(value = MySQLDialect.class, matchSubTypes = false, majorVersion = 5) @RequiresDialect(value = MySQLDialect.class, matchSubTypes = false, majorVersion = 5)
@RequiresDialect(value = MariaDBDialect.class, majorVersion = 5) @RequiresDialect(value = MariaDBDialect.class, majorVersion = 5)
@SkipForDialect(dialectClass = TiDBDialect.class, reason = "TiDB doesn't support stored procedures")
@Jpa( @Jpa(
annotatedClasses = { annotatedClasses = {
Person.class, Person.class,

View File

@ -7,46 +7,48 @@
package org.hibernate.orm.test.query; package org.hibernate.orm.test.query;
import java.util.List; import java.util.List;
import org.hibernate.annotations.Nationalized;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import org.hibernate.annotations.Nationalized; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.hibernate.dialect.SQLServer2008Dialect;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
*/ */
@TestForIssue(jiraKey = "HHH-10183") @TestForIssue(jiraKey = "HHH-10183")
@RequiresDialect(SQLServer2008Dialect.class) @RequiresDialect(value = SQLServerDialect.class, majorVersion = 10)
public class SQLServer2008NationalizedScalarQueryTest extends BaseCoreFunctionalTestCase { @DomainModel(
annotatedClasses = SQLServer2008NationalizedScalarQueryTest.User.class
)
@SessionFactory
public class SQLServer2008NationalizedScalarQueryTest {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { User.class };
}
@Test @Test
public void testScalarResult() { public void testScalarResult(SessionFactoryScope scope) {
User user1 = new User( 1, "Chris" ); User user1 = new User( 1, "Chris" );
User user2 = new User( 2, "Steve" ); User user2 = new User( 2, "Steve" );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
session.save( user1 ); session.save( user1 );
session.save( user2 ); session.save( user2 );
} ); } );
doInHibernate( this::sessionFactory, session -> { scope.inTransaction( session -> {
List<Object[]> users = session.createNativeQuery( List<Object[]> users = session.createNativeQuery(
"select * from users" ).getResultList(); "select * from users" ).getResultList();
assertEquals( 2, users.size() ); assertEquals( 2, users.size() );

View File

@ -9,7 +9,7 @@ package org.hibernate.orm.test.envers.integration.basic;
import java.util.Arrays; import java.util.Arrays;
import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManager;
import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase; import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase;
import org.hibernate.orm.test.envers.Priority; import org.hibernate.orm.test.envers.Priority;
import org.hibernate.orm.test.envers.entities.StrTestEntity; import org.hibernate.orm.test.envers.entities.StrTestEntity;
@ -23,7 +23,7 @@ import junit.framework.Assert;
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/ */
@TestForIssue(jiraKey = "HHH-7246") @TestForIssue(jiraKey = "HHH-7246")
@RequiresDialect(Oracle8iDialect.class) @RequiresDialect(OracleDialect.class)
public class EmptyStringTest extends BaseEnversJPAFunctionalTestCase { public class EmptyStringTest extends BaseEnversJPAFunctionalTestCase {
private Integer emptyId = null; private Integer emptyId = null;
private Integer nullId = null; private Integer nullId = null;

View File

@ -14,7 +14,7 @@ import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.envers.enhanced.OrderedSequenceGenerator; import org.hibernate.envers.enhanced.OrderedSequenceGenerator;
import org.hibernate.envers.enhanced.SequenceIdRevisionEntity; import org.hibernate.envers.enhanced.SequenceIdRevisionEntity;
import org.hibernate.orm.test.envers.BaseEnversFunctionalTestCase; import org.hibernate.orm.test.envers.BaseEnversFunctionalTestCase;
@ -31,7 +31,7 @@ import org.junit.Test;
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/ */
@TestForIssue(jiraKey = "HHH-7669") @TestForIssue(jiraKey = "HHH-7669")
@RequiresDialect(Oracle8iDialect.class) @RequiresDialect(OracleDialect.class)
public class MonotonicRevisionNumberTest extends BaseEnversFunctionalTestCase { public class MonotonicRevisionNumberTest extends BaseEnversFunctionalTestCase {
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {