Code Monkey home page Code Monkey logo

hibernate-test-case-templates's Introduction

Hibernate Test Case Templates

When creating a bug report for any project within the Hibernate family, it's extremely helpful (and, frankly, required) to have an adequate test case available. This is obviously important to make reproducing the issue as easy as possible. But it's also vital longer-term. Nearly every bug fix should include a regression test, which frequently is based on the original reproducer (sometimes, it's the reproducer, verbatim).

To help create useful test cases, we're opening up this repo with various templates. Please see the READMEs in each project's subdir for more info.

As always, this is open source for a reason! If these templates can be improved in any way, please let us know (either through our JIRA instance or through GitHub Issues). Better yet, send us a pull request!

hibernate-test-case-templates's People

Contributors

ahus1 avatar beikov avatar brmeyer avatar dependabot[bot] avatar gbadner avatar gsmet avatar gunnarmorling avatar marko-bekhta avatar mbladel avatar mkomko avatar naros avatar sanne avatar vladmihalcea avatar yrodiere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hibernate-test-case-templates's Issues

Auto-Detect Entities

Although the test case suggests that the project will automatically pick up new JPA entities, I had to add <class> nodes to the persistence.xml to have them picked up. I haven't used bare Hibernate (without Spring Boot) with JPA, so maybe I'm missing something about how this is supposed to work, but I cloned the project, added a src/main/java, and put my entities under there, and got this error:

Once I added the <class> nodes, everything was fine. Did I miss something?

java.lang.IllegalArgumentException: Unknown entity: org.hibernate.bugs.Application
	at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:807)
	at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:788)
	at org.hibernate.bugs.JPAUnitTestCase.hhh123Test(JPAUnitTestCase.java:39)

No Persistence provider for EntityManager named templatePU

In order to debug an issue we are facing with Hibernate version 5.0.11.Final, I've downgraded the hibernate version in the test-case-template-hibernate-orm5 POM as:

<version.org.hibernate>5.0.11.Final</version.org.hibernate>

But that gives the below error when running the added test.

javax.persistence.PersistenceException: No Persistence provider for EntityManager named templatePU

	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
	at org.hibernate.bugs.JPAUnitTestCase.init(JPAUnitTestCase.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at com.intellij.junit4.JUnit4TestRunnerUtil$IgnoreIgnoredTestJUnit4ClassRunner.runChild(JUnit4TestRunnerUtil.java:363)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

The tests and the template works perfectly fine with the provided version 5.2.2.Final but fails with any version used from 5.0.x

Any help on this please?

Version.java throws ArrayIndexOutOfBoundsException

I am using hibernate validator 5.2.2, and executing with Open JDK 11, on Windows 10.

This is code snippet from org.hibernate.validator.internal.util.Version.java

public static int getJavaRelease() {
	// Will return something like 1.8
	String[] specificationVersion = System.getProperty( "java.specification.version" ).split( "\\." );

	return Integer.parseInt( specificationVersion[1] );
}

Integer.parseInt( specificationVersion[1] ) => this line assumes the java.specification.version system property will always have two or more parts. But OpenJDK 11, on Windows10, returning just "11".

Because of this, this class throwing ArrayIndexOutOfBoundsException

JDBC context is initialized while writing schema only with SchemaCreator

I'm trying to write SQL create schema file with SchemaCreator (hibernate 5.6.5.Final). I assumed I wouldn't need a database connection, because it is only writing a sql file based on my classes. When I run this code I observe a lot of warnings "No suitable driver" and "Connections could not be acquired from the underlying database".

When I look into the code I see that the SchemaCreator does have a boolean needsJdbcConnection, only this boolean is never used and a jdbc connection is always setup. This seems like a bug to me.

`
Configuration config = new Configuration();

for (Class<?> type : types) {
config.addAnnotatedClass(type);
}

ServiceRegistry serviceRegistry = config.getStandardServiceRegistryBuilder()
.applySetting(Environment.DIALECT, MmMySqlDialect.class)
.build();
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
Metadata metadata = metadataSources.getMetadataBuilder().build();

SchemaExport schemaExport = new SchemaExport();
schemaExport.setHaltOnError(true);
schemaExport.setFormat(true);
schemaExport.setDelimiter(";");
try {
var tempFile = File.createTempFile("db-create", ".sql");
schemaExport.setOutputFile(tempFile.getAbsolutePath());
schemaExport.createOnly(EnumSet.of(TargetType.SCRIPT), metadata);
catch (IOException e) {
system.out.println(e);
}`

Hi all i got error when using hibernate 5.4.2.Final

i am using eclipse neo when i want build my java application i got error
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named FastMatch

here my persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="FastMatch" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>com.dxtr.hibernate.newOrderSingleEntity</class>
        <properties>
            <property name="eclipselink.logging.level" value="INFO"/>
             <property name="eclipselink.logging.level.sql" value="FINE"/>
            <property name="eclipselink.logging.parameters" value="true"/> 
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://url/tables" />
            <property name="javax.persistence.jdbc.user" value="username" />
            <property name="javax.persistence.jdbc.password" value="password" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="eclipselink.logging.level.connection" value="FINEST"/>
        </properties>
    </persistence-unit>
</persistence>

i have add org.hibernate.jpa.HibernatePersistenceProvider

and this is my pom.xml

<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-core</artifactId>
   <version>5.4.2.Final</version>
 </dependency>
   <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-entitymanager</artifactId>
   <version>5.4.2.Final</version>
 </dependency>
  <dependency>
     <groupId>org.hibernate.javax.persistence</groupId>
     <artifactId>hibernate-jpa-2.1-api</artifactId>
     <version>1.0.0.Final</version>
 </dependency>
 <dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <version>5.1.48</version>
</dependency>

how to solve my problem ? i have try using other solution in google but i cannot solve this problem
regards,

Fuad

Add templates that works with the JPA EntityManager too

We need to support both the Hibernate-specific API and Java Persistence API as well. This way, each issue can be represented exactly how the reporter has bumped into it.

In the test cases that I run for my book, I already have this functionality:

https://github.com/vladmihalcea/high-performance-java-persistence/blob/master/core/src/test/java/com/vladmihalcea/book/hpjp/util/AbstractTest.java

Although I combined both in one base class, which I then extend for each use case, we can have separate templates for Hibernate and JPA.

The hibernate-orm-5 module does not build with Hibernate 5.5.x or 5.6.x

When updating the Hibernate version in the Maven module hibernate-orm-5 to any version of 5.5.x or 5.6.x, the ORMStandaloneTestCase fails with a NullPointerException. There is a breaking change between 5.4.x and 5.5.x, it looks like that starting with 5.5.x the connection properties must be configured in hibernate.properties.

Running org.hibernate.bugs.JPAUnitTestCase
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.195 sec
Running org.hibernate.bugs.ORMUnitTestCase
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.02 sec <<< FAILURE!
org.hibernate.bugs.ORMUnitTestCase  Time elapsed: 0.019 sec  <<< ERROR!
java.lang.ExceptionInInitializerError
	at org.hibernate.testing.cleaner.DatabaseCleanerContext.<clinit>(DatabaseCleanerContext.java:17)
	at org.hibernate.testing.cleaner.DatabaseCleaner.clearSchemas(DatabaseCleaner.java:17)
	at org.hibernate.testing.junit4.BaseUnitTestCase.<clinit>(BaseUnitTestCase.java:39)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:250)
	at org.hibernate.testing.junit4.CustomRunner.getTestInstance(CustomRunner.java:139)
	at org.hibernate.testing.junit4.BeforeClassCallbackHandler.evaluate(BeforeClassCallbackHandler.java:25)
	at org.hibernate.testing.junit4.AfterClassCallbackHandler.evaluate(AfterClassCallbackHandler.java:25)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.lang.IllegalArgumentException: java.lang.NullPointerException
	at org.hibernate.testing.cleaner.JdbcConnectionContext.<clinit>(JdbcConnectionContext.java:46)
	... 25 more
Caused by: java.lang.NullPointerException
	at java.base/java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011)
	at java.base/java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006)
	at java.base/java.util.Properties.put(Properties.java:1337)
	at org.hibernate.testing.cleaner.JdbcConnectionContext.<clinit>(JdbcConnectionContext.java:42)
	... 25 more

The test case can will succeed if you add hibernate.connection.password to hibernate.properties (No value for the property or any value)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.