├── .github
└── dependabot.yml
├── .gitignore
├── Jenkinsfile
├── README.md
├── envers
├── README.md
├── envers-5
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── org
│ │ │ └── hibernate
│ │ │ └── envers
│ │ │ └── bugs
│ │ │ ├── AbstractEnversTestCase.java
│ │ │ └── EnversUnitTestCase.java
│ │ └── resources
│ │ ├── META-INF
│ │ └── persistence.xml
│ │ ├── hibernate.properties
│ │ └── log4j2.properties
├── envers-6
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── org
│ │ │ └── hibernate
│ │ │ └── envers
│ │ │ └── bugs
│ │ │ ├── AbstractEnversTestCase.java
│ │ │ └── EnversUnitTestCase.java
│ │ └── resources
│ │ ├── META-INF
│ │ └── persistence.xml
│ │ ├── hibernate.properties
│ │ └── log4j2.properties
└── envers-7
│ ├── pom.xml
│ └── src
│ └── test
│ ├── java
│ └── org
│ │ └── hibernate
│ │ └── envers
│ │ └── bugs
│ │ ├── AbstractEnversTestCase.java
│ │ └── EnversUnitTestCase.java
│ └── resources
│ ├── META-INF
│ └── persistence.xml
│ ├── hibernate.properties
│ └── log4j2.properties
├── orm
├── README.md
├── hibernate-orm-5
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── org
│ │ │ └── hibernate
│ │ │ └── bugs
│ │ │ ├── JPAUnitTestCase.java
│ │ │ ├── ORMStandaloneTestCase.java
│ │ │ └── ORMUnitTestCase.java
│ │ └── resources
│ │ ├── META-INF
│ │ └── persistence.xml
│ │ ├── hibernate.properties
│ │ └── log4j2.properties
├── hibernate-orm-6
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── org
│ │ │ └── hibernate
│ │ │ └── bugs
│ │ │ ├── JPAUnitTestCase.java
│ │ │ ├── ORMStandaloneTestCase.java
│ │ │ ├── ORMUnitTestCase.java
│ │ │ ├── QuarkusLikeEnhancementContext.java
│ │ │ └── QuarkusLikeORMUnitTestCase.java
│ │ └── resources
│ │ ├── META-INF
│ │ └── persistence.xml
│ │ ├── hibernate.properties
│ │ └── log4j2.properties
└── hibernate-orm-7
│ ├── pom.xml
│ └── src
│ └── test
│ ├── java
│ └── org
│ │ └── hibernate
│ │ └── bugs
│ │ ├── JPAUnitTestCase.java
│ │ ├── ORMStandaloneTestCase.java
│ │ ├── ORMUnitTestCase.java
│ │ ├── QuarkusLikeEnhancementContext.java
│ │ └── QuarkusLikeORMUnitTestCase.java
│ └── resources
│ ├── META-INF
│ └── persistence.xml
│ ├── hibernate.properties
│ └── log4j2.properties
├── pom.xml
├── reactive
├── hibernate-reactive-2
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── org
│ │ │ └── hibernate
│ │ │ └── reactive
│ │ │ ├── bugs
│ │ │ ├── ReactiveStandaloneTestCase.java
│ │ │ └── model
│ │ │ │ └── MyEntity.java
│ │ │ └── util
│ │ │ ├── ConnectionURL.java
│ │ │ ├── Database.java
│ │ │ └── DockerImage.java
│ │ └── resources
│ │ └── log4j2.properties
├── hibernate-reactive-3
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ └── test
│ │ ├── java
│ │ └── org
│ │ │ └── hibernate
│ │ │ └── reactive
│ │ │ ├── bugs
│ │ │ ├── ReactiveStandaloneTestCase.java
│ │ │ └── model
│ │ │ │ └── MyEntity.java
│ │ │ └── util
│ │ │ ├── ConnectionURL.java
│ │ │ ├── Database.java
│ │ │ └── DockerImage.java
│ │ └── resources
│ │ └── log4j2.properties
└── hibernate-reactive-4
│ ├── README.md
│ ├── pom.xml
│ └── src
│ └── test
│ ├── java
│ └── org
│ │ └── hibernate
│ │ └── reactive
│ │ ├── bugs
│ │ ├── ReactiveStandaloneTestCase.java
│ │ └── model
│ │ │ └── MyEntity.java
│ │ └── util
│ │ ├── ConnectionURL.java
│ │ ├── Database.java
│ │ └── DockerImage.java
│ └── resources
│ └── log4j2.properties
├── search
├── README.md
├── hibernate-search-5
│ ├── README.md
│ ├── elasticsearch-2
│ │ └── README.md
│ ├── elasticsearch-5
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── test
│ │ │ ├── java
│ │ │ └── org
│ │ │ │ └── hibernate
│ │ │ │ └── search
│ │ │ │ └── bugs
│ │ │ │ ├── SearchBackendContainer.java
│ │ │ │ ├── SearchTestBase.java
│ │ │ │ ├── SearchTestJunit4Base.java
│ │ │ │ ├── YourAnnotatedEntity.java
│ │ │ │ └── YourIT.java
│ │ │ └── resources
│ │ │ ├── META-INF
│ │ │ └── persistence.xml
│ │ │ ├── hibernate.properties
│ │ │ └── log4j2.properties
│ └── lucene
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ └── test
│ │ ├── java
│ │ └── org
│ │ │ └── hibernate
│ │ │ └── search
│ │ │ └── bugs
│ │ │ ├── SearchTestBase.java
│ │ │ ├── YourAnnotatedEntity.java
│ │ │ └── YourIT.java
│ │ └── resources
│ │ ├── META-INF
│ │ └── persistence.xml
│ │ ├── hibernate.properties
│ │ └── log4j2.properties
├── hibernate-search-6
│ ├── README.md
│ ├── orm-elasticsearch
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── test
│ │ │ ├── java
│ │ │ └── org
│ │ │ │ └── hibernate
│ │ │ │ └── search
│ │ │ │ └── bugs
│ │ │ │ ├── SearchBackendContainer.java
│ │ │ │ ├── SearchTestBase.java
│ │ │ │ ├── SearchTestJunit4Base.java
│ │ │ │ ├── YourAnalysisConfigurer.java
│ │ │ │ ├── YourAnnotatedEntity.java
│ │ │ │ └── YourIT.java
│ │ │ └── resources
│ │ │ ├── META-INF
│ │ │ └── persistence.xml
│ │ │ ├── hibernate.properties
│ │ │ └── log4j2.properties
│ └── orm-lucene
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ └── test
│ │ ├── java
│ │ └── org
│ │ │ └── hibernate
│ │ │ └── search
│ │ │ └── bugs
│ │ │ ├── SearchTestBase.java
│ │ │ ├── YourAnalysisConfigurer.java
│ │ │ ├── YourAnnotatedEntity.java
│ │ │ └── YourIT.java
│ │ └── resources
│ │ ├── META-INF
│ │ └── persistence.xml
│ │ ├── hibernate.properties
│ │ └── log4j2.properties
├── hibernate-search-7
│ ├── README.md
│ ├── orm-elasticsearch
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── test
│ │ │ ├── java
│ │ │ └── org
│ │ │ │ └── hibernate
│ │ │ │ └── search
│ │ │ │ └── bugs
│ │ │ │ ├── SearchBackendContainer.java
│ │ │ │ ├── SearchTestBase.java
│ │ │ │ ├── SearchTestJunit4Base.java
│ │ │ │ ├── YourAnalysisConfigurer.java
│ │ │ │ ├── YourAnnotatedEntity.java
│ │ │ │ ├── YourBytecodeEnhancedIT.java
│ │ │ │ └── YourIT.java
│ │ │ └── resources
│ │ │ ├── META-INF
│ │ │ └── persistence.xml
│ │ │ ├── hibernate.properties
│ │ │ └── log4j2.properties
│ └── orm-lucene
│ │ ├── README.md
│ │ ├── pom.xml
│ │ └── src
│ │ └── test
│ │ ├── java
│ │ └── org
│ │ │ └── hibernate
│ │ │ └── search
│ │ │ └── bugs
│ │ │ ├── SearchTestBase.java
│ │ │ ├── YourAnalysisConfigurer.java
│ │ │ ├── YourAnnotatedEntity.java
│ │ │ ├── YourBytecodeEnhancedIT.java
│ │ │ └── YourIT.java
│ │ └── resources
│ │ ├── META-INF
│ │ └── persistence.xml
│ │ ├── hibernate.properties
│ │ └── log4j2.properties
├── hibernate-search-elasticsearch
│ ├── README.md
│ ├── hibernate-search-elasticsearch-2
│ │ └── README.md
│ └── hibernate-search-elasticsearch-5
│ │ └── README.md
└── hibernate-search-lucene
│ └── README.md
└── validator
├── README.md
├── validator-6
├── README.md
├── pom.xml
└── src
│ └── test
│ ├── java
│ └── org
│ │ └── hibernate
│ │ └── validator
│ │ └── bugs
│ │ ├── YourAnnotatedBean.java
│ │ └── YourTestCase.java
│ └── resources
│ └── log4j2.properties
├── validator-8
├── README.md
├── pom.xml
└── src
│ └── test
│ ├── java
│ └── org
│ │ └── hibernate
│ │ └── validator
│ │ └── bugs
│ │ ├── YourAnnotatedBean.java
│ │ └── YourTestCase.java
│ └── resources
│ └── log4j2.properties
└── validator-9
├── README.md
├── pom.xml
└── src
└── test
├── java
└── org
│ └── hibernate
│ └── validator
│ └── bugs
│ ├── YourAnnotatedBean.java
│ └── YourTestCase.java
└── resources
└── log4j2.properties
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "maven"
4 | directory: "/"
5 | schedule:
6 | interval: "daily"
7 | groups:
8 | quarkus:
9 | patterns:
10 | - "io.quarkus*"
11 | - "io.quarkiverse*"
12 | orm:
13 | patterns:
14 | - "org.hibernate.orm*:*"
15 | search:
16 | patterns:
17 | - "org.hibernate.search:*"
18 | validator:
19 | patterns:
20 | - "org.hibernate.validator:*"
21 | reactive:
22 | patterns:
23 | - "org.hibernate.reactive:*"
24 | reactive-dependencies-jdbc:
25 | patterns:
26 | - "com.mysql:mysql-connector-j"
27 | - "org.mariadb.jdbc:mariadb-java-client"
28 | - "com.ibm.db2:jcc"
29 | - "com.microsoft.sqlserver:mssql-jdbc"
30 | maven-plugins:
31 | patterns:
32 | - "*maven*plugin*"
33 | - "org.apache.maven*:*"
34 | exclude-patterns:
35 | - "io.quarkus*"
36 | - "org.hibernate*"
37 | test:
38 | patterns:
39 | - "org.junit*"
40 | - "org.apache.logging*"
41 | - "com.h2database:*"
42 | - "org.assertj:*"
43 | ignore:
44 | - dependency-name: "org.hibernate.orm.tooling:hibernate-enhance-maven-plugin"
45 | - dependency-name: "org.hibernate:hibernate-core"
46 | update-types: [ "version-update:semver-major", "version-update:semver-minor" ]
47 | - dependency-name: "org.hibernate:*"
48 | update-types: [ "version-update:semver-major" ]
49 | - dependency-name: "org.hibernate.*:*"
50 | update-types: [ "version-update:semver-major" ]
51 | - dependency-name: "com.h2database:h2"
52 | update-types: [ "version-update:semver-major" ]
53 | - dependency-name: "com.github.alexcojocaru:elasticsearch-maven-plugin"
54 | update-types: [ "version-update:semver-major" ]
55 | - dependency-name: "org.elasticsearch:*"
56 | update-types: [ "version-update:semver-major" ]
57 | - dependency-name: "org.elasticsearch.*:*"
58 | update-types: [ "version-update:semver-major" ]
59 | # Major versions of vertx will (most likely) require a new version of Reactive, so will be updated "manually":
60 | - dependency-name: "io.vertx:*"
61 | update-types: [ "version-update:semver-major" ]
62 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | *.iml
3 | .idea
4 |
5 | # Eclipse
6 | .settings
7 | .classpath
8 | .project
9 |
10 | .DS_Store
11 |
12 | *.log
13 |
--------------------------------------------------------------------------------
/Jenkinsfile:
--------------------------------------------------------------------------------
1 | pipeline {
2 | agent {
3 | label 'Worker&&Containers'
4 | }
5 | tools {
6 | jdk 'OpenJDK 17 Latest'
7 | maven 'Apache Maven 3.9'
8 | }
9 | options {
10 | disableConcurrentBuilds(abortPrevious: true)
11 | }
12 | stages {
13 | stage('Build') {
14 | steps {
15 | sh "mvn -B -q clean package -DskipTests=true"
16 | }
17 | }
18 | stage('Test') {
19 | steps {
20 | sh "mvn -B verify"
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Hibernate Test Case Templates
2 |
3 | When creating a bug report for any project within the Hibernate family, it's extremely helpful (and, frankly, required)
4 | to have an adequate test case available. This is obviously important to make reproducing the issue as easy as
5 | possible. But it's also vital longer-term. Nearly every bug fix should include a regression test, which frequently is based
6 | on the original reproducer (sometimes, it's the reproducer, verbatim).
7 |
8 | To help create useful test cases, we're opening up this repo with various templates. Please see the READMEs in each
9 | project's subdir for more info.
10 |
11 | As always, this is open source for a reason! If these templates can be improved in any way, please let us know (either
12 | through our JIRA instance or through GitHub Issues). Better yet, send us a pull request!
--------------------------------------------------------------------------------
/envers/README.md:
--------------------------------------------------------------------------------
1 | # Hibernate Test Case Templates: Envers
2 |
3 | This repo contains test case templates, useful for reporting bugs against Hibernate Envers.
4 |
5 | * EnversUnitTestCase: This provides built-in unit test framework that does much of the heavy lifting for you. All
6 | that is required is your entities, logic, and any necessary settings. Since we nearly always include a regression
7 | test with bug fixes, providing your reproducer using this class simplifies that process. We can then directly add
8 | it, without having to mold it into our existing framework. You're also welcomed to fork hibernate-orm itself, add
9 | your test case directly to the Enver's module test cases (using the template class), then submit it as a pull
10 | request.
11 |
--------------------------------------------------------------------------------
/envers/envers-5/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.hibernate.testcasetemplate
6 | test-case-template-hibernate-envers-5
7 | 1.0.0.Final
8 | Hibernate Envers 5 Test Case Template
9 |
10 |
11 | 2.3.232
12 | 4.13.2
13 | 5.6.15.Final
14 |
15 |
16 |
17 |
18 | org.hibernate
19 | hibernate-envers
20 | ${version.org.hibernate}
21 |
22 |
23 | com.h2database
24 | h2
25 | ${version.com.h2database}
26 |
27 |
28 |
29 | org.hibernate
30 | hibernate-testing
31 | ${version.org.hibernate}
32 | test
33 |
34 |
35 | junit
36 | junit
37 | ${version.junit}
38 | test
39 |
40 |
41 |
42 |
43 |
44 |
45 | org.apache.maven.plugins
46 | maven-compiler-plugin
47 | 3.14.0
48 |
49 | 1.8
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/envers/envers-5/src/test/java/org/hibernate/envers/bugs/AbstractEnversTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Hibernate, Relational Persistence for Idiomatic Java
3 | *
4 | * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5 | * See the lgpl.txt file in the root directory or .
6 | */
7 | package org.hibernate.envers.bugs;
8 |
9 | import org.hibernate.envers.AuditReader;
10 | import org.hibernate.envers.AuditReaderFactory;
11 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
12 |
13 | /**
14 | * @author Chris Cranford
15 | */
16 | public abstract class AbstractEnversTestCase extends BaseCoreFunctionalTestCase {
17 | private AuditReader auditReader;
18 |
19 | protected AuditReader getAuditReader() {
20 | if ( auditReader == null || session == null || !session.isOpen() ) {
21 | auditReader = AuditReaderFactory.get( openSession() );
22 | }
23 | return auditReader;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/envers/envers-5/src/test/java/org/hibernate/envers/bugs/EnversUnitTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Hibernate, Relational Persistence for Idiomatic Java
3 | *
4 | * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5 | * See the lgpl.txt file in the root directory or .
6 | */
7 | package org.hibernate.envers.bugs;
8 |
9 | import org.hibernate.cfg.AvailableSettings;
10 | import org.hibernate.cfg.Configuration;
11 | import org.hibernate.envers.AuditReader;
12 | import org.junit.Test;
13 |
14 | /**
15 | * This template demonstrates how to develop a test case for Hibernate Envers, using
16 | * its built-in unit test framework.
17 | */
18 | public class EnversUnitTestCase extends AbstractEnversTestCase {
19 |
20 | // Add your entities here.
21 | @Override
22 | protected Class[] getAnnotatedClasses() {
23 | return new Class[] {
24 | // Foo.class,
25 | // Bar.class
26 | };
27 | }
28 |
29 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
30 | @Override
31 | protected String[] getMappings() {
32 | return new String[] {
33 | // "Foo.hbm.xml",
34 | // "Bar.hbm.xml"
35 | };
36 | }
37 | // If those mappings reside somewhere other than resources/org/hibernate/test, change this.
38 | @Override
39 | protected String getBaseForMappings() {
40 | return "org/hibernate/test/";
41 | }
42 |
43 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
44 | @Override
45 | protected void configure(Configuration configuration) {
46 | super.configure( configuration );
47 |
48 | configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() );
49 | configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() );
50 | //configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
51 | }
52 |
53 | // Add your tests, using standard JUnit.
54 | @Test
55 | public void hhh123Test() throws Exception {
56 | AuditReader reader = getAuditReader();
57 | // Do stuff...
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/envers/envers-5/src/test/resources/META-INF/persistence.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 | Hibernate test case template Persistence Unit
10 | org.hibernate.jpa.HibernatePersistenceProvider
11 |
12 | false
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/envers/envers-5/src/test/resources/hibernate.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Hibernate, Relational Persistence for Idiomatic Java
3 | #
4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5 | # See the lgpl.txt file in the root directory or .
6 | #
7 |
8 | hibernate.dialect org.hibernate.dialect.H2Dialect
9 | hibernate.connection.driver_class org.h2.Driver
10 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
11 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1
12 | hibernate.connection.username sa
13 |
14 | hibernate.connection.pool_size 5
15 |
16 | hibernate.show_sql false
17 | hibernate.format_sql true
18 |
19 | hibernate.max_fetch_depth 5
20 |
21 | hibernate.cache.region_prefix hibernate.test
22 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
23 |
24 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
25 | hibernate.jdbc.batch_versioned_data true
26 |
27 | javax.persistence.validation.mode=NONE
28 | hibernate.service.allow_crawling=false
29 | hibernate.session.events.log=true
--------------------------------------------------------------------------------
/envers/envers-5/src/test/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | # Set to debug or trace if log4j initialization is failing
2 | status = warn
3 |
4 | # Console appender configuration
5 | appender.console.type = Console
6 | appender.console.name = consoleLogger
7 | appender.console.layout.type = PatternLayout
8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
9 |
10 | # Root logger level
11 | rootLogger.level = info
12 |
13 | # Root logger referring to console appender
14 | rootLogger.appenderRef.stdout.ref = consoleLogger
--------------------------------------------------------------------------------
/envers/envers-6/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.hibernate.testcasetemplate
6 | test-case-template-hibernate-envers-6
7 | 1.0.0.Final
8 | Hibernate Envers 6 Test Case Template
9 |
10 |
11 | 2.3.232
12 | 4.13.2
13 | 6.6.17.Final
14 |
15 |
16 |
17 |
18 |
19 | org.hibernate.orm
20 | hibernate-platform
21 | ${version.org.hibernate.orm}
22 | pom
23 | import
24 |
25 |
26 |
27 |
28 |
29 |
30 | org.hibernate.orm
31 | hibernate-envers
32 |
33 |
34 | com.h2database
35 | h2
36 | ${version.com.h2database}
37 |
38 |
39 |
40 | org.hibernate.orm
41 | hibernate-testing
42 | test
43 |
44 |
45 | junit
46 | junit
47 | ${version.junit}
48 | test
49 |
50 |
51 |
52 |
53 |
54 |
55 | org.apache.maven.plugins
56 | maven-compiler-plugin
57 | 3.14.0
58 |
59 | 11
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/envers/envers-6/src/test/java/org/hibernate/envers/bugs/AbstractEnversTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Hibernate, Relational Persistence for Idiomatic Java
3 | *
4 | * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5 | * See the lgpl.txt file in the root directory or .
6 | */
7 | package org.hibernate.envers.bugs;
8 |
9 | import org.hibernate.envers.AuditReader;
10 | import org.hibernate.envers.AuditReaderFactory;
11 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
12 |
13 | /**
14 | * @author Chris Cranford
15 | */
16 | public abstract class AbstractEnversTestCase extends BaseCoreFunctionalTestCase {
17 | private AuditReader auditReader;
18 |
19 | protected AuditReader getAuditReader() {
20 | if ( auditReader == null || session == null || !session.isOpen() ) {
21 | auditReader = AuditReaderFactory.get( openSession() );
22 | }
23 | return auditReader;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/envers/envers-6/src/test/java/org/hibernate/envers/bugs/EnversUnitTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Hibernate, Relational Persistence for Idiomatic Java
3 | *
4 | * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5 | * See the lgpl.txt file in the root directory or .
6 | */
7 | package org.hibernate.envers.bugs;
8 |
9 | import org.hibernate.cfg.AvailableSettings;
10 | import org.hibernate.cfg.Configuration;
11 | import org.hibernate.envers.AuditReader;
12 | import org.junit.Test;
13 |
14 | /**
15 | * This template demonstrates how to develop a test case for Hibernate Envers, using
16 | * its built-in unit test framework.
17 | */
18 | public class EnversUnitTestCase extends AbstractEnversTestCase {
19 |
20 | // Add your entities here.
21 | @Override
22 | protected Class[] getAnnotatedClasses() {
23 | return new Class[] {
24 | // Foo.class,
25 | // Bar.class
26 | };
27 | }
28 |
29 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
30 | @Override
31 | protected String[] getMappings() {
32 | return new String[] {
33 | // "Foo.hbm.xml",
34 | // "Bar.hbm.xml"
35 | };
36 | }
37 | // If those mappings reside somewhere other than resources/org/hibernate/test, change this.
38 | @Override
39 | protected String getBaseForMappings() {
40 | return "org/hibernate/test/";
41 | }
42 |
43 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
44 | @Override
45 | protected void configure(Configuration configuration) {
46 | super.configure( configuration );
47 |
48 | configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() );
49 | configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() );
50 | //configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
51 | }
52 |
53 | // Add your tests, using standard JUnit.
54 | @Test
55 | public void hhh123Test() throws Exception {
56 | AuditReader reader = getAuditReader();
57 | // Do stuff...
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/envers/envers-6/src/test/resources/META-INF/persistence.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 | Hibernate test case template Persistence Unit
9 | org.hibernate.jpa.HibernatePersistenceProvider
10 |
11 | false
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/envers/envers-6/src/test/resources/hibernate.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Hibernate, Relational Persistence for Idiomatic Java
3 | #
4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5 | # See the lgpl.txt file in the root directory or .
6 | #
7 |
8 | hibernate.dialect org.hibernate.dialect.H2Dialect
9 | hibernate.connection.driver_class org.h2.Driver
10 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
11 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1
12 | hibernate.connection.username sa
13 | hibernate.connection.password
14 |
15 | hibernate.connection.pool_size 5
16 |
17 | hibernate.show_sql false
18 | hibernate.format_sql true
19 |
20 | hibernate.max_fetch_depth 5
21 |
22 | hibernate.cache.region_prefix hibernate.test
23 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
24 |
25 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
26 | hibernate.jdbc.batch_versioned_data true
27 |
28 | jakarta.persistence.validation.mode=NONE
29 | hibernate.service.allow_crawling=false
30 | hibernate.session.events.log=true
--------------------------------------------------------------------------------
/envers/envers-6/src/test/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | # Set to debug or trace if log4j initialization is failing
2 | status = warn
3 |
4 | # Console appender configuration
5 | appender.console.type = Console
6 | appender.console.name = consoleLogger
7 | appender.console.layout.type = PatternLayout
8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
9 |
10 | # Root logger level
11 | rootLogger.level = info
12 |
13 | # Root logger referring to console appender
14 | rootLogger.appenderRef.stdout.ref = consoleLogger
--------------------------------------------------------------------------------
/envers/envers-7/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.hibernate.testcasetemplate
6 | test-case-template-hibernate-envers-7
7 | 1.0.0.Final
8 | Hibernate Envers 7 Test Case Template
9 |
10 |
11 | 2.3.232
12 | 4.13.2
13 | 7.0.0.Final
14 |
15 |
16 |
17 |
18 |
19 | org.hibernate.orm
20 | hibernate-platform
21 | ${version.org.hibernate.orm}
22 | pom
23 | import
24 |
25 |
26 |
27 |
28 |
29 |
30 | org.hibernate.orm
31 | hibernate-envers
32 |
33 |
34 | com.h2database
35 | h2
36 | ${version.com.h2database}
37 |
38 |
39 |
40 | org.hibernate.orm
41 | hibernate-testing
42 | test
43 |
44 |
45 | junit
46 | junit
47 | ${version.junit}
48 | test
49 |
50 |
51 |
52 |
53 |
54 |
55 | org.apache.maven.plugins
56 | maven-compiler-plugin
57 | 3.14.0
58 |
59 | 17
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/envers/envers-7/src/test/java/org/hibernate/envers/bugs/AbstractEnversTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.envers.bugs;
2 |
3 | import org.hibernate.envers.AuditReader;
4 | import org.hibernate.envers.AuditReaderFactory;
5 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
6 |
7 | /**
8 | * @author Chris Cranford
9 | */
10 | public abstract class AbstractEnversTestCase extends BaseCoreFunctionalTestCase {
11 | private AuditReader auditReader;
12 |
13 | protected AuditReader getAuditReader() {
14 | if ( auditReader == null || session == null || !session.isOpen() ) {
15 | auditReader = AuditReaderFactory.get( openSession() );
16 | }
17 | return auditReader;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/envers/envers-7/src/test/java/org/hibernate/envers/bugs/EnversUnitTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.envers.bugs;
2 |
3 | import org.hibernate.cfg.AvailableSettings;
4 | import org.hibernate.cfg.Configuration;
5 | import org.hibernate.envers.AuditReader;
6 | import org.junit.Test;
7 |
8 | /**
9 | * This template demonstrates how to develop a test case for Hibernate Envers, using
10 | * its built-in unit test framework.
11 | */
12 | public class EnversUnitTestCase extends AbstractEnversTestCase {
13 |
14 | // Add your entities here.
15 | @Override
16 | protected Class[] getAnnotatedClasses() {
17 | return new Class[] {
18 | // Foo.class,
19 | // Bar.class
20 | };
21 | }
22 |
23 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
24 | @Override
25 | protected String[] getMappings() {
26 | return new String[] {
27 | // "Foo.hbm.xml",
28 | // "Bar.hbm.xml"
29 | };
30 | }
31 | // If those mappings reside somewhere other than resources/org/hibernate/test, change this.
32 | @Override
33 | protected String getBaseForMappings() {
34 | return "org/hibernate/test/";
35 | }
36 |
37 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
38 | @Override
39 | protected void configure(Configuration configuration) {
40 | super.configure( configuration );
41 |
42 | configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() );
43 | configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() );
44 | //configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
45 | }
46 |
47 | // Add your tests, using standard JUnit.
48 | @Test
49 | public void hhh123Test() throws Exception {
50 | AuditReader reader = getAuditReader();
51 | // Do stuff...
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/envers/envers-7/src/test/resources/META-INF/persistence.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 | Hibernate test case template Persistence Unit
9 | org.hibernate.jpa.HibernatePersistenceProvider
10 |
11 | false
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/envers/envers-7/src/test/resources/hibernate.properties:
--------------------------------------------------------------------------------
1 | hibernate.dialect org.hibernate.dialect.H2Dialect
2 | hibernate.connection.driver_class org.h2.Driver
3 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
4 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1
5 | hibernate.connection.username sa
6 | hibernate.connection.password
7 |
8 | hibernate.connection.pool_size 5
9 |
10 | hibernate.show_sql false
11 | hibernate.format_sql true
12 |
13 | hibernate.max_fetch_depth 5
14 |
15 | hibernate.cache.region_prefix hibernate.test
16 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
17 |
18 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
19 | hibernate.jdbc.batch_versioned_data true
20 |
21 | jakarta.persistence.validation.mode=NONE
22 | hibernate.service.allow_crawling=false
23 | hibernate.session.events.log=true
24 |
--------------------------------------------------------------------------------
/envers/envers-7/src/test/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | # Set to debug or trace if log4j initialization is failing
2 | status = warn
3 |
4 | # Console appender configuration
5 | appender.console.type = Console
6 | appender.console.name = consoleLogger
7 | appender.console.layout.type = PatternLayout
8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
9 |
10 | # Root logger level
11 | rootLogger.level = info
12 |
13 | # Root logger referring to console appender
14 | rootLogger.appenderRef.stdout.ref = consoleLogger
--------------------------------------------------------------------------------
/orm/README.md:
--------------------------------------------------------------------------------
1 | # Hibernate Test Case Templates: ORM
2 |
3 | This repo contains test case templates, useful for reporting bugs against Hibernate ORM.
4 |
5 | Here's a running list of what's available (there are versions of each test case template, one per Hibernate ORM version 5/6/7):
6 |
7 | * `ORMUnitTestCase`: By far, this one's the most helpful. ORM includes a built-in unit test framework that does much
8 | of the heavy lifting for you. All that's required is your entities, logic, and any necessary settings. Since we nearly
9 | always include a regression test with bug fixes, providing your reproducer using this method simplifies the process. We
10 | can then directly commit it, without having to mold it in first. What's even better? Fork hibernate-orm itself,
11 | add your test case directly to a module's unit tests (using the template class), then submit it as a PR!
12 | * `ORMStandaloneTestCase`: This template is standalone and will look familiar. It simply uses a run-of-the-mill ORM setup.
13 | Although it's perfectly acceptable as a reproducer, lean towards `ORMUnitTestCase` whenever possible.
14 | * `QuarkusLikeORMUnitTestCase`: is the same as the `ORMUnitTestCase` with some properties preconfigured to match the behavior that Quarkus has.
15 | **For a detailed step-by-step tutorial about how you should be using our test case templates check out the [following article](http://in.relation.to/2016/01/14/hibernate-jpa-test-case-template/)**.
16 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-5/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.hibernate.testcasetemplate
6 | test-case-template-hibernate-orm-5
7 | 1.0.0.Final
8 | Hibernate ORM 5 Test Case Template
9 |
10 |
11 | 2.3.232
12 | 4.13.2
13 | 5.6.15.Final
14 |
15 |
16 |
17 |
18 | org.hibernate
19 | hibernate-core
20 | ${version.org.hibernate}
21 |
22 |
23 | com.h2database
24 | h2
25 | ${version.com.h2database}
26 |
27 |
28 |
29 |
30 | org.hibernate
31 | hibernate-entitymanager
32 | ${version.org.hibernate}
33 |
34 |
35 | org.hibernate
36 | hibernate-java8
37 | ${version.org.hibernate}
38 |
39 |
40 |
41 | org.hibernate
42 | hibernate-testing
43 | ${version.org.hibernate}
44 | test
45 |
46 |
47 | junit
48 | junit
49 | ${version.junit}
50 | test
51 |
52 |
53 |
54 |
55 |
56 |
57 | org.apache.maven.plugins
58 | maven-compiler-plugin
59 | 3.14.0
60 |
61 | 1.8
62 | 1.8
63 |
64 |
65 |
66 | org.hibernate.orm.tooling
67 | hibernate-enhance-maven-plugin
68 | ${version.org.hibernate}
69 |
70 |
71 |
72 | ${project.build.testOutputDirectory}
73 | ${project.build.testOutputDirectory}
74 | false
75 | false
76 | false
77 | false
78 |
79 | test-compile
80 |
81 | enhance
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.bugs;
2 |
3 | import javax.persistence.EntityManager;
4 | import javax.persistence.EntityManagerFactory;
5 | import javax.persistence.Persistence;
6 |
7 | import org.junit.After;
8 | import org.junit.Before;
9 | import org.junit.Test;
10 |
11 | /**
12 | * This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API.
13 | */
14 | public class JPAUnitTestCase {
15 |
16 | private EntityManagerFactory entityManagerFactory;
17 |
18 | @Before
19 | public void init() {
20 | entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" );
21 | }
22 |
23 | @After
24 | public void destroy() {
25 | entityManagerFactory.close();
26 | }
27 |
28 | // Entities are auto-discovered, so just add them anywhere on class-path
29 | // Add your tests, using standard JUnit.
30 | @Test
31 | public void hhh123Test() throws Exception {
32 | EntityManager entityManager = entityManagerFactory.createEntityManager();
33 | entityManager.getTransaction().begin();
34 | // Do stuff...
35 | entityManager.getTransaction().commit();
36 | entityManager.close();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/ORMStandaloneTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.bugs;
2 |
3 | import org.hibernate.SessionFactory;
4 | import org.hibernate.boot.Metadata;
5 | import org.hibernate.boot.MetadataSources;
6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
7 | import org.junit.Before;
8 | import org.junit.Test;
9 |
10 | /**
11 | * This template demonstrates how to develop a standalone test case for Hibernate ORM. Although this is perfectly
12 | * acceptable as a reproducer, usage of ORMUnitTestCase is preferred!
13 | */
14 | public class ORMStandaloneTestCase {
15 |
16 | private SessionFactory sf;
17 |
18 | @Before
19 | public void setup() {
20 | StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
21 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
22 | .applySetting( "hibernate.show_sql", "true" )
23 | .applySetting( "hibernate.format_sql", "true" )
24 | .applySetting( "hibernate.hbm2ddl.auto", "update" );
25 |
26 | Metadata metadata = new MetadataSources( srb.build() )
27 | // Add your entities here.
28 | // .addAnnotatedClass( Foo.class )
29 | .buildMetadata();
30 |
31 | sf = metadata.buildSessionFactory();
32 | }
33 |
34 | // Add your tests, using standard JUnit.
35 |
36 | @Test
37 | public void hhh123Test() throws Exception {
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/ORMUnitTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 JBoss Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.hibernate.bugs;
17 |
18 | import org.hibernate.Session;
19 | import org.hibernate.Transaction;
20 | import org.hibernate.cfg.AvailableSettings;
21 | import org.hibernate.cfg.Configuration;
22 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
23 | import org.junit.Test;
24 |
25 | /**
26 | * This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework.
27 | * Although ORMStandaloneTestCase is perfectly acceptable as a reproducer, usage of this class is much preferred.
28 | * Since we nearly always include a regression test with bug fixes, providing your reproducer using this method
29 | * simplifies the process.
30 | *
31 | * What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then
32 | * submit it as a PR!
33 | */
34 | public class ORMUnitTestCase extends BaseCoreFunctionalTestCase {
35 |
36 | // Add your entities here.
37 | @Override
38 | protected Class[] getAnnotatedClasses() {
39 | return new Class[] {
40 | // Foo.class,
41 | // Bar.class
42 | };
43 | }
44 |
45 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
46 | @Override
47 | protected String[] getMappings() {
48 | return new String[] {
49 | // "Foo.hbm.xml",
50 | // "Bar.hbm.xml"
51 | };
52 | }
53 | // If those mappings reside somewhere other than resources/org/hibernate/test, change this.
54 | @Override
55 | protected String getBaseForMappings() {
56 | return "org/hibernate/test/";
57 | }
58 |
59 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
60 | @Override
61 | protected void configure(Configuration configuration) {
62 | super.configure( configuration );
63 |
64 | configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() );
65 | configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() );
66 | //configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
67 | }
68 |
69 | // Add your tests, using standard JUnit.
70 | @Test
71 | public void hhh123Test() throws Exception {
72 | // BaseCoreFunctionalTestCase automatically creates the SessionFactory and provides the Session.
73 | Session s = openSession();
74 | Transaction tx = s.beginTransaction();
75 | // Do stuff...
76 | tx.commit();
77 | s.close();
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-5/src/test/resources/META-INF/persistence.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 | Hibernate test case template Persistence Unit
10 | org.hibernate.jpa.HibernatePersistenceProvider
11 |
12 | false
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-5/src/test/resources/hibernate.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Hibernate, Relational Persistence for Idiomatic Java
3 | #
4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5 | # See the lgpl.txt file in the root directory or .
6 | #
7 |
8 | hibernate.dialect org.hibernate.dialect.H2Dialect
9 | hibernate.connection.driver_class org.h2.Driver
10 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
11 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1
12 | hibernate.connection.username sa
13 | hibernate.connection.password
14 |
15 | hibernate.connection.pool_size 5
16 |
17 | hibernate.show_sql false
18 | hibernate.format_sql true
19 |
20 | hibernate.max_fetch_depth 5
21 |
22 | hibernate.cache.region_prefix hibernate.test
23 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
24 |
25 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
26 | hibernate.jdbc.batch_versioned_data true
27 |
28 | javax.persistence.validation.mode=NONE
29 | hibernate.service.allow_crawling=false
30 | hibernate.session.events.log=true
--------------------------------------------------------------------------------
/orm/hibernate-orm-5/src/test/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | # Set to debug or trace if log4j initialization is failing
2 | status = warn
3 |
4 | # Console appender configuration
5 | appender.console.type = Console
6 | appender.console.name = consoleLogger
7 | appender.console.layout.type = PatternLayout
8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
9 |
10 | # Root logger level
11 | rootLogger.level = info
12 |
13 | # Root logger referring to console appender
14 | rootLogger.appenderRef.stdout.ref = consoleLogger
--------------------------------------------------------------------------------
/orm/hibernate-orm-6/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.hibernate.testcasetemplate
6 | test-case-template-hibernate-orm-6
7 | 1.0.0.Final
8 | Hibernate ORM 6 Test Case Template
9 |
10 |
11 | 2.3.232
12 | 5.11.4
13 | 6.6.17.Final
14 | 3.27.3
15 |
16 |
17 |
18 |
19 |
20 | org.hibernate.orm
21 | hibernate-platform
22 | ${version.org.hibernate.orm}
23 | pom
24 | import
25 |
26 |
27 | org.junit
28 | junit-bom
29 | ${version.junit-jupiter}
30 | pom
31 | import
32 |
33 |
34 |
35 |
36 |
37 |
38 | org.hibernate.orm
39 | hibernate-core
40 |
41 |
42 | com.h2database
43 | h2
44 | ${version.com.h2database}
45 |
46 |
47 |
48 | org.hibernate.orm
49 | hibernate-testing
50 | test
51 |
52 |
53 | org.junit.jupiter
54 | junit-jupiter
55 | test
56 |
57 |
58 | org.junit.platform
59 | junit-platform-launcher
60 | test
61 |
62 |
63 | org.junit.jupiter
64 | junit-jupiter-engine
65 | test
66 |
67 |
68 | org.assertj
69 | assertj-core
70 | ${version.org.assertj.assertj-core}
71 | test
72 |
73 |
74 |
75 |
76 |
77 |
78 | org.apache.maven.plugins
79 | maven-compiler-plugin
80 | 3.14.0
81 |
82 | 11
83 |
84 |
85 |
86 | org.hibernate.orm.tooling
87 | hibernate-enhance-maven-plugin
88 | ${version.org.hibernate.orm}
89 |
90 |
91 |
92 | ${project.build.testOutputDirectory}
93 | ${project.build.testOutputDirectory}
94 | false
95 | false
96 | false
97 | false
98 |
99 | test-compile
100 |
101 | enhance
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.bugs;
2 |
3 | import org.junit.jupiter.api.AfterEach;
4 | import org.junit.jupiter.api.BeforeEach;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import jakarta.persistence.EntityManager;
8 | import jakarta.persistence.EntityManagerFactory;
9 | import jakarta.persistence.Persistence;
10 |
11 | /**
12 | * This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API.
13 | */
14 | class JPAUnitTestCase {
15 |
16 | private EntityManagerFactory entityManagerFactory;
17 |
18 | @BeforeEach
19 | void init() {
20 | entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" );
21 | }
22 |
23 | @AfterEach
24 | void destroy() {
25 | entityManagerFactory.close();
26 | }
27 |
28 | // Entities are auto-discovered, so just add them anywhere on class-path
29 | // Add your tests, using standard JUnit.
30 | @Test
31 | void hhh123Test() throws Exception {
32 | EntityManager entityManager = entityManagerFactory.createEntityManager();
33 | entityManager.getTransaction().begin();
34 | // Do stuff...
35 | entityManager.getTransaction().commit();
36 | entityManager.close();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/ORMStandaloneTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.bugs;
2 |
3 | import org.hibernate.SessionFactory;
4 | import org.hibernate.boot.Metadata;
5 | import org.hibernate.boot.MetadataSources;
6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
7 |
8 | import org.junit.jupiter.api.BeforeEach;
9 | import org.junit.jupiter.api.Test;
10 |
11 | /**
12 | * This template demonstrates how to develop a standalone test case for Hibernate ORM. Although this is perfectly
13 | * acceptable as a reproducer, usage of ORMUnitTestCase is preferred!
14 | */
15 | class ORMStandaloneTestCase {
16 |
17 | private SessionFactory sf;
18 |
19 | @BeforeEach
20 | void setup() {
21 | StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
22 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
23 | .applySetting( "hibernate.show_sql", "true" )
24 | .applySetting( "hibernate.format_sql", "true" )
25 | .applySetting( "hibernate.hbm2ddl.auto", "update" );
26 |
27 | Metadata metadata = new MetadataSources( srb.build() )
28 | // Add your entities here.
29 | // .addAnnotatedClass( Foo.class )
30 | .buildMetadata();
31 |
32 | sf = metadata.buildSessionFactory();
33 | }
34 |
35 | // Add your tests, using standard JUnit 5:
36 | @Test
37 | void hhh123Test() throws Exception {
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/ORMUnitTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 JBoss Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.hibernate.bugs;
17 |
18 | import org.hibernate.cfg.AvailableSettings;
19 |
20 | import org.hibernate.testing.orm.junit.DomainModel;
21 | import org.hibernate.testing.orm.junit.ServiceRegistry;
22 | import org.hibernate.testing.orm.junit.SessionFactory;
23 | import org.hibernate.testing.orm.junit.SessionFactoryScope;
24 | import org.hibernate.testing.orm.junit.Setting;
25 | import org.junit.jupiter.api.Test;
26 |
27 | /**
28 | * This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework.
29 | * Although ORMStandaloneTestCase is perfectly acceptable as a reproducer, usage of this class is much preferred.
30 | * Since we nearly always include a regression test with bug fixes, providing your reproducer using this method
31 | * simplifies the process.
32 | *
33 | * What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then
34 | * submit it as a PR!
35 | */
36 | @DomainModel(
37 | annotatedClasses = {
38 | // Add your entities here.
39 | // Foo.class,
40 | // Bar.class
41 | },
42 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
43 | xmlMappings = {
44 | // "org/hibernate/test/Foo.hbm.xml",
45 | // "org/hibernate/test/Bar.hbm.xml"
46 | }
47 | )
48 | @ServiceRegistry(
49 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
50 | settings = {
51 | // For your own convenience to see generated queries:
52 | @Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
53 | @Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
54 | // @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
55 |
56 | // Add your own settings that are a part of your quarkus configuration:
57 | // @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ),
58 | }
59 | )
60 | @SessionFactory
61 | class ORMUnitTestCase {
62 |
63 | // Add your tests, using standard JUnit 5.
64 | @Test
65 | void hhh123Test(SessionFactoryScope scope) throws Exception {
66 | scope.inTransaction( session -> {
67 | // Do stuff...
68 | } );
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/QuarkusLikeEnhancementContext.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.bugs;
2 |
3 | import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
4 | import org.hibernate.bytecode.enhance.spi.UnloadedField;
5 | import org.hibernate.bytecode.enhance.spi.UnsupportedEnhancementStrategy;
6 |
7 | public class QuarkusLikeEnhancementContext extends DefaultEnhancementContext {
8 | @Override
9 | public boolean doBiDirectionalAssociationManagement(final UnloadedField field) {
10 | //Don't enable automatic association management as it's often too surprising.
11 | //Also, there's several cases in which its semantics are of unspecified,
12 | //such as what should happen when dealing with ordered collections.
13 | return false;
14 | }
15 |
16 | @Override
17 | public UnsupportedEnhancementStrategy getUnsupportedEnhancementStrategy() {
18 | // We expect model classes to be enhanced.
19 | // Lack of enhancement could lead to many problems,
20 | // from bad performance, to Quarkus-specific optimizations causing errors/data loss,
21 | // to incorrect generated bytecode (references to non-existing methods).
22 | // If something prevents enhancement, it's just safer to have Hibernate ORM's enhancer fail
23 | // with a clear error message pointing to the application class that needs to be fixed.
24 | return UnsupportedEnhancementStrategy.FAIL;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/QuarkusLikeORMUnitTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 JBoss Inc
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.hibernate.bugs;
17 |
18 | import org.hibernate.cfg.AvailableSettings;
19 |
20 | import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
21 | import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
22 | import org.hibernate.testing.orm.junit.DomainModel;
23 | import org.hibernate.testing.orm.junit.ServiceRegistry;
24 | import org.hibernate.testing.orm.junit.SessionFactory;
25 | import org.hibernate.testing.orm.junit.SessionFactoryScope;
26 | import org.hibernate.testing.orm.junit.Setting;
27 | import org.junit.jupiter.api.Test;
28 |
29 | /**
30 | * This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework.
31 | *
32 | * What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then
33 | * submit it as a PR!
34 | */
35 | @DomainModel(
36 | annotatedClasses = {
37 | // Add your entities here, e.g.:
38 | // Foo.class,
39 | // Bar.class
40 | }
41 | )
42 | @ServiceRegistry(
43 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
44 | settings = {
45 | // For your own convenience to see generated queries:
46 | @Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
47 | @Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
48 | // @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
49 |
50 | // Other settings that will make your test case run under similar configuration that Quarkus is using by default:
51 | @Setting(name = AvailableSettings.PREFERRED_POOLED_OPTIMIZER, value = "pooled-lo"),
52 | @Setting(name = AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, value = "16"),
53 | @Setting(name = AvailableSettings.BATCH_FETCH_STYLE, value = "PADDED"),
54 | @Setting(name = AvailableSettings.QUERY_PLAN_CACHE_MAX_SIZE, value = "2048"),
55 | @Setting(name = AvailableSettings.DEFAULT_NULL_ORDERING, value = "none"),
56 | @Setting(name = AvailableSettings.IN_CLAUSE_PARAMETER_PADDING, value = "true"),
57 | @Setting(name = AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, value = "none"),
58 | @Setting(name = AvailableSettings.ORDER_UPDATES, value = "true"),
59 |
60 | // Add your own settings that are a part of your quarkus configuration:
61 | // @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ),
62 | }
63 | )
64 | @SessionFactory
65 | @BytecodeEnhanced
66 | @CustomEnhancementContext(QuarkusLikeEnhancementContext.class)
67 | class QuarkusLikeORMUnitTestCase {
68 |
69 | // Add your tests, using standard JUnit.
70 | @Test
71 | void hhh123Test(SessionFactoryScope scope) throws Exception {
72 | scope.inTransaction( session -> {
73 | // Do stuff...
74 | } );
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-6/src/test/resources/META-INF/persistence.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 | Hibernate test case template Persistence Unit
9 | org.hibernate.jpa.HibernatePersistenceProvider
10 |
11 | false
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-6/src/test/resources/hibernate.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Hibernate, Relational Persistence for Idiomatic Java
3 | #
4 | # License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5 | # See the lgpl.txt file in the root directory or .
6 | #
7 |
8 | hibernate.dialect org.hibernate.dialect.H2Dialect
9 | hibernate.connection.driver_class org.h2.Driver
10 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
11 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1
12 | hibernate.connection.username sa
13 | hibernate.connection.password
14 |
15 | hibernate.connection.pool_size 5
16 |
17 | hibernate.show_sql false
18 | hibernate.format_sql true
19 |
20 | hibernate.max_fetch_depth 5
21 |
22 | hibernate.cache.region_prefix hibernate.test
23 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
24 |
25 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
26 | hibernate.jdbc.batch_versioned_data true
27 |
28 | jakarta.persistence.validation.mode=NONE
29 | hibernate.service.allow_crawling=false
30 | hibernate.session.events.log=true
--------------------------------------------------------------------------------
/orm/hibernate-orm-6/src/test/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | # Set to debug or trace if log4j initialization is failing
2 | status = warn
3 |
4 | # Console appender configuration
5 | appender.console.type = Console
6 | appender.console.name = consoleLogger
7 | appender.console.layout.type = PatternLayout
8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
9 |
10 | # Root logger level
11 | rootLogger.level = info
12 |
13 | # Root logger referring to console appender
14 | rootLogger.appenderRef.stdout.ref = consoleLogger
--------------------------------------------------------------------------------
/orm/hibernate-orm-7/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | org.hibernate.testcasetemplate
6 | test-case-template-hibernate-orm-7
7 | 1.0.0.Final
8 | Hibernate ORM 7 Test Case Template
9 |
10 |
11 | 2.3.232
12 | 5.12.2
13 | 7.0.0.Final
14 | 3.27.3
15 |
16 |
17 |
18 |
19 |
20 | org.hibernate.orm
21 | hibernate-platform
22 | ${version.org.hibernate.orm}
23 | pom
24 | import
25 |
26 |
27 | org.junit
28 | junit-bom
29 | ${version.junit-jupiter}
30 | pom
31 | import
32 |
33 |
34 |
35 |
36 |
37 |
38 | org.hibernate.orm
39 | hibernate-core
40 |
41 |
42 | com.h2database
43 | h2
44 | ${version.com.h2database}
45 |
46 |
47 |
48 | org.hibernate.orm
49 | hibernate-testing
50 | test
51 |
52 |
53 | org.junit.jupiter
54 | junit-jupiter
55 | test
56 |
57 |
58 | org.junit.platform
59 | junit-platform-launcher
60 | test
61 |
62 |
63 | org.junit.jupiter
64 | junit-jupiter-engine
65 | test
66 |
67 |
68 | org.assertj
69 | assertj-core
70 | ${version.org.assertj.assertj-core}
71 | test
72 |
73 |
74 |
75 |
76 |
77 |
78 | org.apache.maven.plugins
79 | maven-compiler-plugin
80 | 3.14.0
81 |
82 | 17
83 |
84 |
85 |
86 | org.hibernate.orm
87 | hibernate-maven-plugin
88 | ${version.org.hibernate.orm}
89 |
90 |
91 |
92 | ${project.build.testOutputDirectory}
93 | ${project.build.testOutputDirectory}
94 | false
95 | false
96 | false
97 | false
98 |
99 | test-compile
100 |
101 | enhance
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.bugs;
2 |
3 | import org.junit.jupiter.api.AfterEach;
4 | import org.junit.jupiter.api.BeforeEach;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import jakarta.persistence.EntityManager;
8 | import jakarta.persistence.EntityManagerFactory;
9 | import jakarta.persistence.Persistence;
10 |
11 | /**
12 | * This template demonstrates how to develop a test case for Hibernate ORM, using the Java Persistence API.
13 | */
14 | class JPAUnitTestCase {
15 |
16 | private EntityManagerFactory entityManagerFactory;
17 |
18 | @BeforeEach
19 | void init() {
20 | entityManagerFactory = Persistence.createEntityManagerFactory( "templatePU" );
21 | }
22 |
23 | @AfterEach
24 | void destroy() {
25 | entityManagerFactory.close();
26 | }
27 |
28 | // Entities are auto-discovered, so just add them anywhere on class-path
29 | // Add your tests, using standard JUnit.
30 | @Test
31 | void hhh123Test() throws Exception {
32 | EntityManager entityManager = entityManagerFactory.createEntityManager();
33 | entityManager.getTransaction().begin();
34 | // Do stuff...
35 | entityManager.getTransaction().commit();
36 | entityManager.close();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/ORMStandaloneTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.bugs;
2 |
3 | import org.hibernate.SessionFactory;
4 | import org.hibernate.boot.Metadata;
5 | import org.hibernate.boot.MetadataSources;
6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
7 |
8 | import org.junit.jupiter.api.BeforeEach;
9 | import org.junit.jupiter.api.Test;
10 |
11 | /**
12 | * This template demonstrates how to develop a standalone test case for Hibernate ORM. Although this is perfectly
13 | * acceptable as a reproducer, usage of ORMUnitTestCase is preferred!
14 | */
15 | class ORMStandaloneTestCase {
16 |
17 | private SessionFactory sf;
18 |
19 | @BeforeEach
20 | void setup() {
21 | StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
22 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
23 | .applySetting( "hibernate.show_sql", "true" )
24 | .applySetting( "hibernate.format_sql", "true" )
25 | .applySetting( "hibernate.hbm2ddl.auto", "update" );
26 |
27 | Metadata metadata = new MetadataSources( srb.build() )
28 | // Add your entities here.
29 | // .addAnnotatedClass( Foo.class )
30 | .buildMetadata();
31 |
32 | sf = metadata.buildSessionFactory();
33 | }
34 |
35 | // Add your tests, using standard JUnit 5:
36 | @Test
37 | void hhh123Test() throws Exception {
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/ORMUnitTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.bugs;
2 |
3 | import org.hibernate.cfg.AvailableSettings;
4 |
5 | import org.hibernate.testing.orm.junit.DomainModel;
6 | import org.hibernate.testing.orm.junit.ServiceRegistry;
7 | import org.hibernate.testing.orm.junit.SessionFactory;
8 | import org.hibernate.testing.orm.junit.SessionFactoryScope;
9 | import org.hibernate.testing.orm.junit.Setting;
10 | import org.junit.jupiter.api.Test;
11 |
12 | /**
13 | * This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework.
14 | * Although ORMStandaloneTestCase is perfectly acceptable as a reproducer, usage of this class is much preferred.
15 | * Since we nearly always include a regression test with bug fixes, providing your reproducer using this method
16 | * simplifies the process.
17 | *
18 | * What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then
19 | * submit it as a PR!
20 | */
21 | @DomainModel(
22 | annotatedClasses = {
23 | // Add your entities here.
24 | // Foo.class,
25 | // Bar.class
26 | },
27 | // If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
28 | xmlMappings = {
29 | // "org/hibernate/test/Foo.hbm.xml",
30 | // "org/hibernate/test/Bar.hbm.xml"
31 | }
32 | )
33 | @ServiceRegistry(
34 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
35 | settings = {
36 | // For your own convenience to see generated queries:
37 | @Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
38 | @Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
39 | // @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
40 |
41 | // Add your own settings that are a part of your quarkus configuration:
42 | // @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ),
43 | }
44 | )
45 | @SessionFactory
46 | class ORMUnitTestCase {
47 |
48 | // Add your tests, using standard JUnit 5.
49 | @Test
50 | void hhh123Test(SessionFactoryScope scope) throws Exception {
51 | scope.inTransaction( session -> {
52 | // Do stuff...
53 | } );
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/QuarkusLikeEnhancementContext.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.bugs;
2 |
3 | import org.hibernate.bytecode.enhance.spi.DefaultEnhancementContext;
4 | import org.hibernate.bytecode.enhance.spi.UnloadedField;
5 | import org.hibernate.bytecode.enhance.spi.UnsupportedEnhancementStrategy;
6 |
7 | public class QuarkusLikeEnhancementContext extends DefaultEnhancementContext {
8 | @Override
9 | public boolean doBiDirectionalAssociationManagement(final UnloadedField field) {
10 | //Don't enable automatic association management as it's often too surprising.
11 | //Also, there's several cases in which its semantics are of unspecified,
12 | //such as what should happen when dealing with ordered collections.
13 | return false;
14 | }
15 |
16 | @Override
17 | public UnsupportedEnhancementStrategy getUnsupportedEnhancementStrategy() {
18 | // We expect model classes to be enhanced.
19 | // Lack of enhancement could lead to many problems,
20 | // from bad performance, to Quarkus-specific optimizations causing errors/data loss,
21 | // to incorrect generated bytecode (references to non-existing methods).
22 | // If something prevents enhancement, it's just safer to have Hibernate ORM's enhancer fail
23 | // with a clear error message pointing to the application class that needs to be fixed.
24 | return UnsupportedEnhancementStrategy.FAIL;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-7/src/test/java/org/hibernate/bugs/QuarkusLikeORMUnitTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.bugs;
2 |
3 | import org.hibernate.cfg.AvailableSettings;
4 |
5 | import org.hibernate.testing.bytecode.enhancement.CustomEnhancementContext;
6 | import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
7 | import org.hibernate.testing.orm.junit.DomainModel;
8 | import org.hibernate.testing.orm.junit.ServiceRegistry;
9 | import org.hibernate.testing.orm.junit.SessionFactory;
10 | import org.hibernate.testing.orm.junit.SessionFactoryScope;
11 | import org.hibernate.testing.orm.junit.Setting;
12 | import org.junit.jupiter.api.Test;
13 |
14 | /**
15 | * This template demonstrates how to develop a test case for Hibernate ORM, using its built-in unit test framework.
16 | *
17 | * What's even better? Fork hibernate-orm itself, add your test case directly to a module's unit tests, then
18 | * submit it as a PR!
19 | */
20 | @DomainModel(
21 | annotatedClasses = {
22 | // Add your entities here, e.g.:
23 | // Foo.class,
24 | // Bar.class
25 | }
26 | )
27 | @ServiceRegistry(
28 | // Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
29 | settings = {
30 | // For your own convenience to see generated queries:
31 | @Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
32 | @Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
33 | // @Setting( name = AvailableSettings.GENERATE_STATISTICS, value = "true" ),
34 |
35 | // Other settings that will make your test case run under similar configuration that Quarkus is using by default:
36 | @Setting(name = AvailableSettings.PREFERRED_POOLED_OPTIMIZER, value = "pooled-lo"),
37 | @Setting(name = AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, value = "16"),
38 | @Setting(name = AvailableSettings.QUERY_PLAN_CACHE_MAX_SIZE, value = "2048"),
39 | @Setting(name = AvailableSettings.DEFAULT_NULL_ORDERING, value = "none"),
40 | @Setting(name = AvailableSettings.IN_CLAUSE_PARAMETER_PADDING, value = "true"),
41 | @Setting(name = AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, value = "none"),
42 | @Setting(name = AvailableSettings.ORDER_UPDATES, value = "true"),
43 |
44 | // Add your own settings that are a part of your quarkus configuration:
45 | // @Setting( name = AvailableSettings.SOME_CONFIGURATION_PROPERTY, value = "SOME_VALUE" ),
46 | }
47 | )
48 | @SessionFactory
49 | @BytecodeEnhanced
50 | @CustomEnhancementContext(QuarkusLikeEnhancementContext.class)
51 | class QuarkusLikeORMUnitTestCase {
52 |
53 | // Add your tests, using standard JUnit.
54 | @Test
55 | void hhh123Test(SessionFactoryScope scope) throws Exception {
56 | scope.inTransaction( session -> {
57 | // Do stuff...
58 | } );
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-7/src/test/resources/META-INF/persistence.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 | Hibernate test case template Persistence Unit
9 | org.hibernate.jpa.HibernatePersistenceProvider
10 |
11 | false
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-7/src/test/resources/hibernate.properties:
--------------------------------------------------------------------------------
1 | hibernate.dialect org.hibernate.dialect.H2Dialect
2 | hibernate.connection.driver_class org.h2.Driver
3 | #hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
4 | hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1
5 | hibernate.connection.username sa
6 | hibernate.connection.password
7 |
8 | hibernate.connection.pool_size 5
9 |
10 | hibernate.show_sql false
11 | hibernate.format_sql true
12 |
13 | hibernate.max_fetch_depth 5
14 |
15 | hibernate.cache.region_prefix hibernate.test
16 | hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
17 |
18 | # NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
19 | hibernate.jdbc.batch_versioned_data true
20 |
21 | jakarta.persistence.validation.mode=NONE
22 | hibernate.service.allow_crawling=false
23 | hibernate.session.events.log=true
24 |
--------------------------------------------------------------------------------
/orm/hibernate-orm-7/src/test/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | # Set to debug or trace if log4j initialization is failing
2 | status = warn
3 |
4 | # Console appender configuration
5 | appender.console.type = Console
6 | appender.console.name = consoleLogger
7 | appender.console.layout.type = PatternLayout
8 | appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
9 |
10 | # Root logger level
11 | rootLogger.level = info
12 |
13 | # Root logger referring to console appender
14 | rootLogger.appenderRef.stdout.ref = consoleLogger
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | org.hibernate.testcasetemplate
6 | hibernate-testcasetemplate-aggregator
7 | 1.0-SNAPSHOT
8 | pom
9 | Hibernate Test Case Templates - Aggregator POM
10 | An aggregator POM to build all test case templates in one command, or to simplify configuration of dependabot
11 |
12 | orm/hibernate-orm-5
13 | orm/hibernate-orm-6
14 | orm/hibernate-orm-7
15 | envers/envers-5
16 | envers/envers-6
17 | envers/envers-7
18 | search/hibernate-search-5/elasticsearch-5
19 | search/hibernate-search-5/lucene
20 | search/hibernate-search-6/orm-elasticsearch
21 | search/hibernate-search-6/orm-lucene
22 | search/hibernate-search-7/orm-elasticsearch
23 | search/hibernate-search-7/orm-lucene
24 | validator/validator-6
25 | validator/validator-8
26 | validator/validator-9
27 | reactive/hibernate-reactive-2
28 | reactive/hibernate-reactive-3
29 | reactive/hibernate-reactive-4
30 |
31 |
32 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-2/README.md:
--------------------------------------------------------------------------------
1 | # Hibernate Test Case Templates: Reactive
2 |
3 | This repo contains test case templates, useful for reporting bugs
4 | against [Hibernate Reactive](https://hibernate.org/reactive/).
5 |
6 | The template contains examples of tests written using both the Mutiny and Stage API.
7 | The bug report can be written either with one or the other.
8 |
9 | The database is started via [Testcontainers](https://java.testcontainers.org/).
10 | It's possible to select a different database by changing the value of the constant `SELECT_DB`.
11 |
12 | The package [org.hibernate.reactive.util](src/test/java/org/hibernate/reactive/util) contains:
13 |
14 | * `ConnectionUrl`: The JDBC urls to connect to databases started following the instructions in the
15 | [PODMAN.md](https://github.com/hibernate/hibernate-reactive/blob/main/podman.md) file
16 | in the [Hibernate Reactive GitHub repository](https://github.com/hibernate/hibernate-reactive)
17 | * `Database`: Containers configuration via [Testcontainers](https://java.testcontainers.org/)
18 | * `DockerImage`: Utility class for the creation of a `DockerImageName` to use with Testcontainers
19 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-2/src/test/java/org/hibernate/reactive/bugs/ReactiveStandaloneTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.bugs;
2 |
3 | import org.hibernate.SessionFactory;
4 | import org.hibernate.boot.Metadata;
5 | import org.hibernate.boot.MetadataSources;
6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
7 | import org.hibernate.reactive.bugs.model.MyEntity;
8 | import org.hibernate.reactive.mutiny.Mutiny;
9 | import org.hibernate.reactive.provider.ReactiveServiceRegistryBuilder;
10 | import org.hibernate.reactive.stage.Stage;
11 | import org.hibernate.reactive.util.Database;
12 |
13 | import org.junit.jupiter.api.AfterAll;
14 | import org.junit.jupiter.api.BeforeAll;
15 | import org.junit.jupiter.api.Test;
16 | import org.junit.jupiter.api.extension.ExtendWith;
17 |
18 | import io.smallrye.mutiny.Uni;
19 | import io.vertx.junit5.VertxExtension;
20 | import io.vertx.junit5.VertxTestContext;
21 | import java.util.concurrent.CompletableFuture;
22 | import org.testcontainers.containers.JdbcDatabaseContainer;
23 |
24 | /**
25 | * Demonstrates how to develop a standalone test case for Hibernate Reactive using
26 | * the {@link org.hibernate.reactive.mutiny.Mutiny.SessionFactory}
27 | * or {@link org.hibernate.reactive.stage.Stage.SessionFactory}.
28 | *
29 | * It uses the {@link VertxExtension} to ease the testing of async code using JUnit.
30 | *
31 | *
32 | * There are two test methods (feel free to pick your favorite):
33 | *
34 | *
{@link #testWithMutiny(VertxTestContext)} for using the Mutiny API
35 | *
{@link #testWithStage(VertxTestContext)} for using the Stage API
36 | *
37 | *
38 | *
39 | * Databases for the tests start via Testcontainers.
40 | * The configuration of the containers is in {@link Database} and the test
41 | * can run on different databases by changing the value of {@link #SELECTED_DB}.
42 | *
43 | */
44 | @ExtendWith(VertxExtension.class)
45 | public class ReactiveStandaloneTestCase {
46 |
47 | /**
48 | * The selected database to run the test against.
49 | * If the value is set to null, no container will start.
50 | *
51 | * @see Database
52 | */
53 | private static final Database SELECTED_DB = Database.POSTGRESQL;
54 |
55 | private static JdbcDatabaseContainer> container;
56 | private static SessionFactory sf;
57 |
58 | @BeforeAll
59 | public static void startContainer() {
60 | if ( SELECTED_DB != null ) {
61 | container = SELECTED_DB.startContainer();
62 | }
63 | }
64 |
65 | @BeforeAll
66 | public static void setup() {
67 | StandardServiceRegistryBuilder srb = new ReactiveServiceRegistryBuilder()
68 | .applySetting( "hibernate.connection.url", container.getJdbcUrl() )
69 | .applySetting( "hibernate.connection.username", container.getUsername() )
70 | .applySetting( "hibernate.connection.password", container.getPassword() )
71 | .applySetting( "hibernate.hbm2ddl.auto", "update" )
72 | .applySetting( "hibernate.show_sql", "true" )
73 | .applySetting( "hibernate.highlight_sql", "true" )
74 | .applySetting( "hibernate.format_sql", "true" );
75 |
76 | Metadata metadata = new MetadataSources( srb.build() )
77 | // Add your entities here.
78 | .addAnnotatedClass( MyEntity.class )
79 | .buildMetadata();
80 |
81 | sf = metadata.buildSessionFactory();
82 | }
83 |
84 | @Test
85 | public void testWithMutiny(VertxTestContext context) {
86 | Mutiny.SessionFactory mutinySf = sf.unwrap( Mutiny.SessionFactory.class );
87 | mutinySf
88 | // Example of transactional block
89 | .withTransaction( session -> {
90 | return Uni.createFrom().voidItem();
91 | } )
92 | // Subscribe the uni and wait until it completes
93 | .subscribe().with( res -> context.completeNow(), context::failNow );
94 | }
95 |
96 | @Test
97 | public void testWithStage(VertxTestContext context) {
98 | Stage.SessionFactory stageSf = sf.unwrap( Stage.SessionFactory.class );
99 | stageSf
100 | // Example of transactional block
101 | .withTransaction( session -> {
102 | return CompletableFuture.completedFuture( null );
103 | } )
104 | // Stop the test when the CompletionStage completes
105 | .whenComplete( (res, err) -> {
106 | if ( err != null ) {
107 | context.failNow( err );
108 | }
109 | else {
110 | context.completeNow();
111 | }
112 | } );
113 | }
114 |
115 | // It's important to always close the factory at the end of the tests.
116 | @AfterAll
117 | public static void closeSessionFactory() {
118 | if ( sf != null ) {
119 | sf.close();
120 | }
121 | }
122 |
123 | @AfterAll
124 | public static void stopContainer() {
125 | if ( container != null ) {
126 | container.stop();
127 | }
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-2/src/test/java/org/hibernate/reactive/bugs/model/MyEntity.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.bugs.model;
2 |
3 | import jakarta.persistence.Entity;
4 | import jakarta.persistence.Id;
5 |
6 | /**
7 | * An entity to starts with.
8 | */
9 | @Entity
10 | public class MyEntity {
11 |
12 | @Id
13 | private Long id;
14 | private String name;
15 |
16 | public Long getId() {
17 | return id;
18 | }
19 |
20 | public void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return "MyEntity(" + id + ":" + name + ")";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-2/src/test/java/org/hibernate/reactive/util/ConnectionURL.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.util;
2 |
3 | /**
4 | * JDBC URL connection strings for the property {@link org.hibernate.reactive.provider.Settings#URL} when the database
5 | * is started the instructions from the
6 | * Hibernate Reactive GitHub repository.
7 | */
8 | public final class ConnectionURL {
9 | public static final String POSTGRES = "jdbc:postgresql://localhost:5432/hreact?user=hreact&password=hreact";
10 | public static final String COCKROACH = "jdbc:cockroachdb://localhost:26257/postgres?sslmode=disable&user=root";
11 | public static final String MYSQL = "jdbc:mysql://localhost/hreact?user=hreact&password=hreact";
12 | public static final String MARIA = "jdbc:mariadb://localhost:3306/hreact?user=hreact&password=hreact";
13 | public static final String MSSQL = "jdbc:sqlserver://localhost:1433;Encrypt=false;user=sa;password=~!HReact!~";
14 | public static final String DB2 = "jdbc:db2://localhost:50000/hreact:user=hreact;password=hreact;";
15 | public static final String ORACLE = "jdbc:oracle:thin:hreact/hreact@localhost:1521/hreact?user=hreact&password=hreact";
16 | }
17 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-2/src/test/java/org/hibernate/reactive/util/Database.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.util;
2 |
3 | import java.util.function.Supplier;
4 | import org.testcontainers.containers.CockroachContainer;
5 | import org.testcontainers.containers.Db2Container;
6 | import org.testcontainers.containers.JdbcDatabaseContainer;
7 | import org.testcontainers.containers.MSSQLServerContainer;
8 | import org.testcontainers.containers.MariaDBContainer;
9 | import org.testcontainers.containers.MySQLContainer;
10 | import org.testcontainers.containers.OracleContainer;
11 | import org.testcontainers.containers.PostgreSQLContainer;
12 |
13 | import static org.hibernate.reactive.util.DockerImage.imageName;
14 |
15 | /**
16 | * The only purpose of this class is to make it easier to switch among the available databases
17 | * for the unit tests.
18 | *
19 | * It's a wrapper around the testcontainers classes.
20 | */
21 | public enum Database {
22 | POSTGRESQL( () -> new PostgreSQLContainer<>( imageName( "postgres", "16.3" ) ) ),
23 | MYSQL( () -> new MySQLContainer<>( imageName( "mysql", "8.4.0" ) ) ),
24 | MARIADB( () -> new MariaDBContainer<>( imageName( "mariadb", "11.4.2" ) ) ),
25 | DB2( () -> new Db2Container( imageName( "icr.io", "db2_community/db2", "12.1.0.0" ) ).acceptLicense() ),
26 | COCKROACHDB( () -> new CockroachContainer( imageName( "cockroachdb/cockroach", "v24.1.0" ) ) ),
27 | ORACLE( Database::newOracleContainer ),
28 | MSSQL( Database::newMSSqlServer );
29 |
30 | private final Supplier> containerSupplier;
31 |
32 | Database(Supplier> supplier) {
33 | this.containerSupplier = supplier;
34 | }
35 |
36 | /**
37 | * Start the container using testcontainers and print the log on System.out.
38 | */
39 | public JdbcDatabaseContainer> startContainer() {
40 | return startContainer( true );
41 | }
42 |
43 | /**
44 | * Start the database using testcontainers.
45 | *
46 | * @param enableLog if true, print the container log
47 | */
48 | public JdbcDatabaseContainer> startContainer(boolean enableLog) {
49 | JdbcDatabaseContainer> jdbcDatabaseContainer = containerSupplier.get();
50 | jdbcDatabaseContainer
51 | .withLogConsumer( of -> logContainerOutput( of.getUtf8String() ) )
52 | .withReuse( true )
53 | .start();
54 | return jdbcDatabaseContainer;
55 | }
56 |
57 | private static MSSQLServerContainer> newMSSqlServer() {
58 | return new MSSQLServerContainer<>( imageName( "mcr.microsoft.com", "mssql/server", "2022-latest" ) )
59 | .acceptLicense();
60 | }
61 |
62 | private static OracleContainer newOracleContainer() {
63 | return new OracleContainer( imageName( "gvenzl/oracle-free", "23-slim-faststart" )
64 | .asCompatibleSubstituteFor( "gvenzl/oracle-xe" ) )
65 | .withStartupAttempts( 1 )
66 |
67 | // We need to limit the maximum amount of CPUs being used by the container;
68 | // otherwise the hardcoded memory configuration of the DB might not be enough to successfully boot it.
69 | // See https://github.com/gvenzl/oci-oracle-xe/issues/64
70 | // I choose to limit it to "2 cpus": should be more than enough for any local testing needs,
71 | // and keeps things simple.
72 | .withCreateContainerCmdModifier( cmd -> cmd.getHostConfig().withCpuCount( 2L ) );
73 | }
74 |
75 | private static void logContainerOutput(String line) {
76 | System.out.print( line );
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-2/src/test/java/org/hibernate/reactive/util/DockerImage.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.util;
2 |
3 | import org.testcontainers.utility.DockerImageName;
4 |
5 | /**
6 | * A utility class with methods to generate {@link DockerImageName} for testcontainers.
7 | *
8 | * Testcontainers might not work if the image required is available in multiple different registries (for example when
9 | * using podman instead of docker).
10 | * These methods make sure to pick a registry as default.
11 | *
12 | */
13 | public final class DockerImage {
14 |
15 | public static final String DEFAULT_REGISTRY = "docker.io";
16 |
17 | public static DockerImageName imageName(String image, String version) {
18 | return imageName( DEFAULT_REGISTRY, image, version );
19 | }
20 |
21 | public static DockerImageName imageName(String registry, String image, String version) {
22 | return DockerImageName
23 | .parse( registry + "/" + image + ":" + version )
24 | .asCompatibleSubstituteFor( image );
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-2/src/test/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | # Root logger level
2 | rootLogger.level = info
3 | rootLogger.appenderRefs = console
4 | rootLogger.appenderRef.console.ref = console
5 |
6 | # Print the selected dialect information
7 | logger.hibernate-dialect.name = org.hibernate.orm.dialect
8 | logger.hibernate-dialect.level = debug
9 |
10 | # SQL logging disabled by default to speed test suite execution
11 | # It can also be enabled by setting the environment variable:
12 | # JAVA_TOOL_OPTIONS='-Dhibernate.show_sql=true'
13 | logger.hibernate.name = org.hibernate.SQL
14 | logger.hibernate.level = info
15 |
16 | # Setting level TRACE will show when a connection is opened/closed
17 | logger.sql-connection.name = org.hibernate.reactive.pool.impl
18 | logger.sql-connection.level = info
19 |
20 | # Setting level to TRACE will show parameters values for SQL queries
21 | logger.sql-parameters-values.name = org.hibernate.type
22 | logger.sql-parameters-values.level = info
23 |
24 | appender.console.name = console
25 | appender.console.type = Console
26 | appender.console.layout.type = PatternLayout
27 | appender.console.layout.pattern = %highlight{[%p]} %m%n
28 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-3/README.md:
--------------------------------------------------------------------------------
1 | # Hibernate Test Case Templates: Reactive
2 |
3 | This repo contains test case templates, useful for reporting bugs
4 | against [Hibernate Reactive](https://hibernate.org/reactive/).
5 |
6 | The template contains examples of tests written using both the Mutiny and Stage API.
7 | The bug report can be written either with one or the other.
8 |
9 | The database is started via [Testcontainers](https://java.testcontainers.org/).
10 | It's possible to select a different database by changing the value of the constant `SELECT_DB`.
11 |
12 | The package [org.hibernate.reactive.util](src/test/java/org/hibernate/reactive/util) contains:
13 |
14 | * `ConnectionUrl`: The JDBC urls to connect to databases started following the instructions in the
15 | [PODMAN.md](https://github.com/hibernate/hibernate-reactive/blob/main/podman.md) file
16 | in the [Hibernate Reactive GitHub repository](https://github.com/hibernate/hibernate-reactive)
17 | * `Database`: Containers configuration via [Testcontainers](https://java.testcontainers.org/)
18 | * `DockerImage`: Utility class for the creation of a `DockerImageName` to use with Testcontainers
19 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-3/src/test/java/org/hibernate/reactive/bugs/ReactiveStandaloneTestCase.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.bugs;
2 |
3 | import org.hibernate.SessionFactory;
4 | import org.hibernate.boot.Metadata;
5 | import org.hibernate.boot.MetadataSources;
6 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
7 | import org.hibernate.reactive.bugs.model.MyEntity;
8 | import org.hibernate.reactive.mutiny.Mutiny;
9 | import org.hibernate.reactive.provider.ReactiveServiceRegistryBuilder;
10 | import org.hibernate.reactive.stage.Stage;
11 | import org.hibernate.reactive.util.Database;
12 |
13 | import org.junit.jupiter.api.AfterAll;
14 | import org.junit.jupiter.api.BeforeAll;
15 | import org.junit.jupiter.api.Test;
16 | import org.junit.jupiter.api.extension.ExtendWith;
17 |
18 | import io.smallrye.mutiny.Uni;
19 | import io.vertx.junit5.VertxExtension;
20 | import io.vertx.junit5.VertxTestContext;
21 | import java.util.concurrent.CompletableFuture;
22 | import org.testcontainers.containers.JdbcDatabaseContainer;
23 |
24 | /**
25 | * Demonstrates how to develop a standalone test case for Hibernate Reactive using
26 | * the {@link org.hibernate.reactive.mutiny.Mutiny.SessionFactory}
27 | * or {@link org.hibernate.reactive.stage.Stage.SessionFactory}.
28 | *
29 | * It uses the {@link VertxExtension} to ease the testing of async code using JUnit.
30 | *
31 | *
32 | * There are two test methods (feel free to pick your favorite):
33 | *
34 | *
{@link #testWithMutiny(VertxTestContext)} for using the Mutiny API
35 | *
{@link #testWithStage(VertxTestContext)} for using the Stage API
36 | *
37 | *
38 | *
39 | * Databases for the tests start via Testcontainers.
40 | * The configuration of the containers is in {@link Database} and the test
41 | * can run on different databases by changing the value of {@link #SELECTED_DB}.
42 | *
43 | */
44 | @ExtendWith(VertxExtension.class)
45 | public class ReactiveStandaloneTestCase {
46 |
47 | /**
48 | * The selected database to run the test against.
49 | * If the value is set to null, no container will start.
50 | *
51 | * @see Database
52 | */
53 | private static final Database SELECTED_DB = Database.POSTGRESQL;
54 |
55 | private static JdbcDatabaseContainer> container;
56 | private static SessionFactory sf;
57 |
58 | @BeforeAll
59 | public static void startContainer() {
60 | if ( SELECTED_DB != null ) {
61 | container = SELECTED_DB.startContainer();
62 | }
63 | }
64 |
65 | @BeforeAll
66 | public static void setup() {
67 | StandardServiceRegistryBuilder srb = new ReactiveServiceRegistryBuilder()
68 | .applySetting( "hibernate.connection.url", container.getJdbcUrl() )
69 | .applySetting( "hibernate.connection.username", container.getUsername() )
70 | .applySetting( "hibernate.connection.password", container.getPassword() )
71 | .applySetting( "hibernate.hbm2ddl.auto", "update" )
72 | .applySetting( "hibernate.show_sql", "true" )
73 | .applySetting( "hibernate.highlight_sql", "true" )
74 | .applySetting( "hibernate.format_sql", "true" );
75 |
76 | Metadata metadata = new MetadataSources( srb.build() )
77 | // Add your entities here.
78 | .addAnnotatedClass( MyEntity.class )
79 | .buildMetadata();
80 |
81 | sf = metadata.buildSessionFactory();
82 | }
83 |
84 | @Test
85 | public void testWithMutiny(VertxTestContext context) {
86 | Mutiny.SessionFactory mutinySf = sf.unwrap( Mutiny.SessionFactory.class );
87 | mutinySf
88 | // Example of transactional block
89 | .withTransaction( session -> {
90 | return Uni.createFrom().voidItem();
91 | } )
92 | // Subscribe the uni and wait until it completes
93 | .subscribe().with( res -> context.completeNow(), context::failNow );
94 | }
95 |
96 | @Test
97 | public void testWithStage(VertxTestContext context) {
98 | Stage.SessionFactory stageSf = sf.unwrap( Stage.SessionFactory.class );
99 | stageSf
100 | // Example of transactional block
101 | .withTransaction( session -> {
102 | return CompletableFuture.completedFuture( null );
103 | } )
104 | // Stop the test when the CompletionStage completes
105 | .whenComplete( (res, err) -> {
106 | if ( err != null ) {
107 | context.failNow( err );
108 | }
109 | else {
110 | context.completeNow();
111 | }
112 | } );
113 | }
114 |
115 | // It's important to always close the factory at the end of the tests.
116 | @AfterAll
117 | public static void closeSessionFactory() {
118 | if ( sf != null ) {
119 | sf.close();
120 | }
121 | }
122 |
123 | @AfterAll
124 | public static void stopContainer() {
125 | if ( container != null ) {
126 | container.stop();
127 | }
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-3/src/test/java/org/hibernate/reactive/bugs/model/MyEntity.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.bugs.model;
2 |
3 | import jakarta.persistence.Entity;
4 | import jakarta.persistence.Id;
5 |
6 | /**
7 | * An entity to starts with.
8 | */
9 | @Entity
10 | public class MyEntity {
11 |
12 | @Id
13 | private Long id;
14 | private String name;
15 |
16 | public Long getId() {
17 | return id;
18 | }
19 |
20 | public void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return "MyEntity(" + id + ":" + name + ")";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-3/src/test/java/org/hibernate/reactive/util/ConnectionURL.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.util;
2 |
3 | /**
4 | * JDBC URL connection strings for the property {@link org.hibernate.reactive.provider.Settings#URL} when the database
5 | * is started the instructions from the
6 | * Hibernate Reactive GitHub repository.
7 | */
8 | public final class ConnectionURL {
9 | public static final String POSTGRES = "jdbc:postgresql://localhost:5432/hreact?user=hreact&password=hreact";
10 | public static final String COCKROACH = "jdbc:cockroachdb://localhost:26257/postgres?sslmode=disable&user=root";
11 | public static final String MYSQL = "jdbc:mysql://localhost/hreact?user=hreact&password=hreact";
12 | public static final String MARIA = "jdbc:mariadb://localhost:3306/hreact?user=hreact&password=hreact";
13 | public static final String MSSQL = "jdbc:sqlserver://localhost:1433;Encrypt=false;user=sa;password=~!HReact!~";
14 | public static final String DB2 = "jdbc:db2://localhost:50000/hreact:user=hreact;password=hreact;";
15 | public static final String ORACLE = "jdbc:oracle:thin:hreact/hreact@localhost:1521/hreact?user=hreact&password=hreact";
16 | }
17 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-3/src/test/java/org/hibernate/reactive/util/Database.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.util;
2 |
3 | import java.util.function.Supplier;
4 | import org.testcontainers.containers.CockroachContainer;
5 | import org.testcontainers.containers.Db2Container;
6 | import org.testcontainers.containers.JdbcDatabaseContainer;
7 | import org.testcontainers.containers.MSSQLServerContainer;
8 | import org.testcontainers.containers.MariaDBContainer;
9 | import org.testcontainers.containers.MySQLContainer;
10 | import org.testcontainers.containers.OracleContainer;
11 | import org.testcontainers.containers.PostgreSQLContainer;
12 |
13 | import static org.hibernate.reactive.util.DockerImage.imageName;
14 |
15 | /**
16 | * The only purpose of this class is to make it easier to switch among the available databases
17 | * for the unit tests.
18 | *
19 | * It's a wrapper around the testcontainers classes.
20 | */
21 | public enum Database {
22 | POSTGRESQL( () -> new PostgreSQLContainer<>( imageName( "postgres", "16.3" ) ) ),
23 | MYSQL( () -> new MySQLContainer<>( imageName( "mysql", "8.4.0" ) ) ),
24 | MARIADB( () -> new MariaDBContainer<>( imageName( "mariadb", "11.4.2" ) ) ),
25 | DB2( () -> new Db2Container( imageName( "icr.io", "db2_community/db2", "12.1.0.0" ) ).acceptLicense() ),
26 | COCKROACHDB( () -> new CockroachContainer( imageName( "cockroachdb/cockroach", "v24.1.0" ) ) ),
27 | ORACLE( Database::newOracleContainer ),
28 | MSSQL( Database::newMSSqlServer );
29 |
30 | private final Supplier> containerSupplier;
31 |
32 | Database(Supplier> supplier) {
33 | this.containerSupplier = supplier;
34 | }
35 |
36 | /**
37 | * Start the container using testcontainers and print the log on System.out.
38 | */
39 | public JdbcDatabaseContainer> startContainer() {
40 | return startContainer( true );
41 | }
42 |
43 | /**
44 | * Start the database using testcontainers.
45 | *
46 | * @param enableLog if true, print the container log
47 | */
48 | public JdbcDatabaseContainer> startContainer(boolean enableLog) {
49 | JdbcDatabaseContainer> jdbcDatabaseContainer = containerSupplier.get();
50 | jdbcDatabaseContainer
51 | .withLogConsumer( of -> logContainerOutput( of.getUtf8String() ) )
52 | .withReuse( true )
53 | .start();
54 | return jdbcDatabaseContainer;
55 | }
56 |
57 | private static MSSQLServerContainer> newMSSqlServer() {
58 | return new MSSQLServerContainer<>( imageName( "mcr.microsoft.com", "mssql/server", "2022-latest" ) )
59 | .acceptLicense();
60 | }
61 |
62 | private static OracleContainer newOracleContainer() {
63 | return new OracleContainer( imageName( "gvenzl/oracle-free", "23-slim-faststart" )
64 | .asCompatibleSubstituteFor( "gvenzl/oracle-xe" ) )
65 | .withStartupAttempts( 1 )
66 |
67 | // We need to limit the maximum amount of CPUs being used by the container;
68 | // otherwise the hardcoded memory configuration of the DB might not be enough to successfully boot it.
69 | // See https://github.com/gvenzl/oci-oracle-xe/issues/64
70 | // I choose to limit it to "2 cpus": should be more than enough for any local testing needs,
71 | // and keeps things simple.
72 | .withCreateContainerCmdModifier( cmd -> cmd.getHostConfig().withCpuCount( 2L ) );
73 | }
74 |
75 | private static void logContainerOutput(String line) {
76 | System.out.print( line );
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-3/src/test/java/org/hibernate/reactive/util/DockerImage.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.util;
2 |
3 | import org.testcontainers.utility.DockerImageName;
4 |
5 | /**
6 | * A utility class with methods to generate {@link DockerImageName} for testcontainers.
7 | *
8 | * Testcontainers might not work if the image required is available in multiple different registries (for example when
9 | * using podman instead of docker).
10 | * These methods make sure to pick a registry as default.
11 | *
12 | */
13 | public final class DockerImage {
14 |
15 | public static final String DEFAULT_REGISTRY = "docker.io";
16 |
17 | public static DockerImageName imageName(String image, String version) {
18 | return imageName( DEFAULT_REGISTRY, image, version );
19 | }
20 |
21 | public static DockerImageName imageName(String registry, String image, String version) {
22 | return DockerImageName
23 | .parse( registry + "/" + image + ":" + version )
24 | .asCompatibleSubstituteFor( image );
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-3/src/test/resources/log4j2.properties:
--------------------------------------------------------------------------------
1 | # Root logger level
2 | rootLogger.level = info
3 | rootLogger.appenderRefs = console
4 | rootLogger.appenderRef.console.ref = console
5 |
6 | # Print the selected dialect information
7 | logger.hibernate-dialect.name = org.hibernate.orm.dialect
8 | logger.hibernate-dialect.level = debug
9 |
10 | # SQL logging disabled by default to speed test suite execution
11 | # It can also be enabled by setting the environment variable:
12 | # JAVA_TOOL_OPTIONS='-Dhibernate.show_sql=true'
13 | logger.hibernate.name = org.hibernate.SQL
14 | logger.hibernate.level = info
15 |
16 | # Setting level TRACE will show when a connection is opened/closed
17 | logger.sql-connection.name = org.hibernate.reactive.pool.impl
18 | logger.sql-connection.level = info
19 |
20 | # Setting level to TRACE will show parameters values for SQL queries
21 | logger.sql-parameters-values.name = org.hibernate.type
22 | logger.sql-parameters-values.level = info
23 |
24 | appender.console.name = console
25 | appender.console.type = Console
26 | appender.console.layout.type = PatternLayout
27 | appender.console.layout.pattern = %highlight{[%p]} %m%n
28 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-4/README.md:
--------------------------------------------------------------------------------
1 | # Hibernate Test Case Templates: Reactive
2 |
3 | This repo contains test case templates, useful for reporting bugs
4 | against [Hibernate Reactive](https://hibernate.org/reactive/).
5 |
6 | The template contains examples of tests written using both the Mutiny and Stage API.
7 | The bug report can be written either with one or the other.
8 |
9 | The database is started via [Testcontainers](https://java.testcontainers.org/).
10 | It's possible to select a different database by changing the value of the constant `SELECT_DB`.
11 |
12 | The package [org.hibernate.reactive.util](src/test/java/org/hibernate/reactive/util) contains:
13 |
14 | * `ConnectionUrl`: The JDBC urls to connect to databases started following the instructions in the
15 | [PODMAN.md](https://github.com/hibernate/hibernate-reactive/blob/main/podman.md) file
16 | in the [Hibernate Reactive GitHub repository](https://github.com/hibernate/hibernate-reactive)
17 | * `Database`: Containers configuration via [Testcontainers](https://java.testcontainers.org/)
18 | * `DockerImage`: Utility class for the creation of a `DockerImageName` to use with Testcontainers
19 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-4/src/test/java/org/hibernate/reactive/bugs/model/MyEntity.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.bugs.model;
2 |
3 | import jakarta.persistence.Entity;
4 | import jakarta.persistence.Id;
5 |
6 | /**
7 | * An entity to starts with.
8 | */
9 | @Entity
10 | public class MyEntity {
11 |
12 | @Id
13 | private Long id;
14 | private String name;
15 |
16 | public Long getId() {
17 | return id;
18 | }
19 |
20 | public void setId(Long id) {
21 | this.id = id;
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return "MyEntity(" + id + ":" + name + ")";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-4/src/test/java/org/hibernate/reactive/util/ConnectionURL.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.util;
2 |
3 | /**
4 | * JDBC URL connection strings for the property {@link org.hibernate.reactive.provider.Settings#URL} when the database
5 | * is started the instructions from the
6 | * Hibernate Reactive GitHub repository.
7 | */
8 | public final class ConnectionURL {
9 | public static final String POSTGRES = "jdbc:postgresql://localhost:5432/hreact?user=hreact&password=hreact";
10 | public static final String COCKROACH = "jdbc:cockroachdb://localhost:26257/postgres?sslmode=disable&user=root";
11 | public static final String MYSQL = "jdbc:mysql://localhost/hreact?user=hreact&password=hreact";
12 | public static final String MARIA = "jdbc:mariadb://localhost:3306/hreact?user=hreact&password=hreact";
13 | public static final String MSSQL = "jdbc:sqlserver://localhost:1433;Encrypt=false;user=sa;password=~!HReact!~";
14 | public static final String DB2 = "jdbc:db2://localhost:50000/hreact:user=hreact;password=hreact;";
15 | public static final String ORACLE = "jdbc:oracle:thin:hreact/hreact@localhost:1521/hreact?user=hreact&password=hreact";
16 | }
17 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-4/src/test/java/org/hibernate/reactive/util/Database.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.util;
2 |
3 | import java.util.function.Supplier;
4 | import org.testcontainers.containers.CockroachContainer;
5 | import org.testcontainers.containers.Db2Container;
6 | import org.testcontainers.containers.JdbcDatabaseContainer;
7 | import org.testcontainers.containers.MSSQLServerContainer;
8 | import org.testcontainers.containers.MariaDBContainer;
9 | import org.testcontainers.containers.MySQLContainer;
10 | import org.testcontainers.containers.OracleContainer;
11 | import org.testcontainers.containers.PostgreSQLContainer;
12 |
13 | import static org.hibernate.reactive.util.DockerImage.imageName;
14 |
15 | /**
16 | * The only purpose of this class is to make it easier to switch among the available databases
17 | * for the unit tests.
18 | *
19 | * It's a wrapper around the testcontainers classes.
20 | */
21 | public enum Database {
22 | POSTGRESQL( () -> new PostgreSQLContainer<>( imageName( "postgres", "16.3" ) ) ),
23 | MYSQL( () -> new MySQLContainer<>( imageName( "mysql", "8.4.0" ) ) ),
24 | MARIADB( () -> new MariaDBContainer<>( imageName( "mariadb", "11.4.2" ) ) ),
25 | DB2( () -> new Db2Container( imageName( "icr.io", "db2_community/db2", "12.1.0.0" ) ).acceptLicense() ),
26 | COCKROACHDB( () -> new CockroachContainer( imageName( "cockroachdb/cockroach", "v24.1.0" ) ) ),
27 | ORACLE( Database::newOracleContainer ),
28 | MSSQL( Database::newMSSqlServer );
29 |
30 | private final Supplier> containerSupplier;
31 |
32 | Database(Supplier> supplier) {
33 | this.containerSupplier = supplier;
34 | }
35 |
36 | /**
37 | * Start the container using testcontainers and print the log on System.out.
38 | */
39 | public JdbcDatabaseContainer> startContainer() {
40 | return startContainer( true );
41 | }
42 |
43 | /**
44 | * Start the database using testcontainers.
45 | *
46 | * @param enableLog if true, print the container log
47 | */
48 | public JdbcDatabaseContainer> startContainer(boolean enableLog) {
49 | JdbcDatabaseContainer> jdbcDatabaseContainer = containerSupplier.get();
50 | jdbcDatabaseContainer
51 | .withLogConsumer( of -> logContainerOutput( of.getUtf8String() ) )
52 | .withReuse( true )
53 | .start();
54 | return jdbcDatabaseContainer;
55 | }
56 |
57 | private static MSSQLServerContainer> newMSSqlServer() {
58 | return new MSSQLServerContainer<>( imageName( "mcr.microsoft.com", "mssql/server", "2022-latest" ) )
59 | .acceptLicense();
60 | }
61 |
62 | private static OracleContainer newOracleContainer() {
63 | return new OracleContainer( imageName( "gvenzl/oracle-free", "23-slim-faststart" )
64 | .asCompatibleSubstituteFor( "gvenzl/oracle-xe" ) )
65 | .withStartupAttempts( 1 )
66 |
67 | // We need to limit the maximum amount of CPUs being used by the container;
68 | // otherwise the hardcoded memory configuration of the DB might not be enough to successfully boot it.
69 | // See https://github.com/gvenzl/oci-oracle-xe/issues/64
70 | // I choose to limit it to "2 cpus": should be more than enough for any local testing needs,
71 | // and keeps things simple.
72 | .withCreateContainerCmdModifier( cmd -> cmd.getHostConfig().withCpuCount( 2L ) );
73 | }
74 |
75 | private static void logContainerOutput(String line) {
76 | System.out.print( line );
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/reactive/hibernate-reactive-4/src/test/java/org/hibernate/reactive/util/DockerImage.java:
--------------------------------------------------------------------------------
1 | package org.hibernate.reactive.util;
2 |
3 | import org.testcontainers.utility.DockerImageName;
4 |
5 | /**
6 | * A utility class with methods to generate {@link DockerImageName} for testcontainers.
7 | *
8 | * Testcontainers might not work if the image required is available in multiple different registries (for example when
9 | * using podman instead of docker).
10 | * These methods make sure to pick a registry as default.
11 | *