Skip to content

hibernate 7 #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dep_build_v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java_version: ['11', '17']
java_version: ['17', '21']
env:
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
strategy:
fail-fast: false
matrix:
# 20-Dec-2022, tatu: Build now requires JDK 11; won't yet work with JDK 17
java_version: [ '11']
# Hibernate 7 requires Java 17+
java_version: [ '17' ]
env:
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
steps:
Expand Down
8 changes: 8 additions & 0 deletions hibernate4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ Hibernate (https://hibernate.org) version 4.x data types.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<!-- Inherited from oss-base. Generate PackageVersion.java.-->
<groupId>com.google.code.maven-replacer-plugin</groupId>
Expand Down
8 changes: 8 additions & 0 deletions hibernate5-jakarta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ Hibernate (https://hibernate.org) version 5.5 with Jakarta data types.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<!-- Inherited from oss-base. Generate PackageVersion.java.-->
<groupId>com.google.code.maven-replacer-plugin</groupId>
Expand Down
8 changes: 8 additions & 0 deletions hibernate5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ Hibernate (https://hibernate.org) version 5.x data types.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<!-- Inherited from oss-base. Generate PackageVersion.java.-->
<groupId>com.google.code.maven-replacer-plugin</groupId>
Expand Down
8 changes: 8 additions & 0 deletions hibernate5_2-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<!-- Don't generate a jar -->
<groupId>org.apache.maven.plugins</groupId>
Expand Down
8 changes: 8 additions & 0 deletions hibernate6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ Hibernate (https://hibernate.org/) version 6.x with Jakarta data types.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<!-- Inherited from oss-base. Generate PackageVersion.java.-->
<groupId>com.google.code.maven-replacer-plugin</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.proxy.pojo.BasicLazyInitializer;
Expand Down Expand Up @@ -249,6 +249,7 @@ private String getIdentifierPropertyName(final LazyInitializer init) {
if (_mapping != null) {
idName = _mapping.getIdentifierPropertyName(init.getEntityName());
} else {
// no unit tests rely on this next call and Hibernate 7 does not support it
idName = ProxySessionReader.getIdentifierPropertyName(init);
if (idName == null) {
idName = ProxyReader.getIdentifierPropertyName(init);
Expand Down Expand Up @@ -301,47 +302,12 @@ static String getIdentifierPropertyName(LazyInitializer init) {
}
}

/**
* Hibernate 5.2 broke abi compatibility of org.hibernate.proxy.LazyInitializer.getSession()
* The api contract changed
* from org.hibernate.proxy.LazyInitializer.getSession()Lorg.hibernate.engine.spi.SessionImplementor;
* to org.hibernate.proxy.LazyInitializer.getSession()Lorg.hibernate.engine.spi.SharedSessionContractImplementor
*
* On hibernate 5.2 the interface SessionImplementor extends SharedSessionContractImplementor.
* And an instance of org.hibernate.internal.SessionImpl is returned from getSession().
*/
protected static class ProxySessionReader {

/**
* The getSession method must be executed using reflection for compatibility purpose.
* For efficiency keep the method cached.
*/
protected static final Method lazyInitializerGetSessionMethod;

static {
try {
lazyInitializerGetSessionMethod = LazyInitializer.class.getMethod("getSession");
} catch (Exception e) {
// should never happen: the class and method exists in all versions of hibernate 5
throw new RuntimeException(e);
}
}

static String getIdentifierPropertyName(LazyInitializer init) {
final Object session;
try{
session = lazyInitializerGetSessionMethod.invoke(init);
} catch (Exception e) {
// Should never happen
throw new RuntimeException(e);
}
if(session instanceof SessionImplementor){
SessionFactoryImplementor factory = ((SessionImplementor)session).getFactory();
return factory.getIdentifierPropertyName(init.getEntityName());
}else if (session != null) {
// Should never happen: session should be an instance of org.hibernate.internal.SessionImpl
// factory = session.getClass().getMethod("getFactory").invoke(session);
throw new RuntimeException("Session is not instance of SessionImplementor");
final SharedSessionContractImplementor session = init.getSession();
if (session != null) {
SessionFactoryImplementor factory = session.getFactory();
return factory.getIdentifierPropertyName(init.getEntityName());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private Session openTemporarySessionForLoading(PersistentCollection coll) {
session.setHibernateFlushMode(FlushMode.MANUAL);

persistenceContext.addUninitializedDetachedCollection(
((SessionFactoryImplementor) _sessionFactory).getMetamodel().collectionPersister(coll.getRole()),
((SessionFactoryImplementor) _sessionFactory).getMappingMetamodel().getCollectionDescriptor(coll.getRole()),
coll
);

Expand Down
34 changes: 17 additions & 17 deletions hibernate6/src/test/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Customer</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Employee</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Office</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Order</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.OrderDetail</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.OrderDetailId</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Payment</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.PaymentId</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Product</class>
<properties>
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="jakarta.persistence.jdbc.user" value=""/>
<property name="jakarta.persistence.jdbc.password" value=""/>
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'classpath:/classicmodels.sql'"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
</properties>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Customer</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Employee</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Office</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Order</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.OrderDetail</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.OrderDetailId</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Payment</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.PaymentId</class>
<class>data.com.fasterxml.jackson.datatype.hibernate6.Product</class>
<properties>
<property name="jakarta.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="jakarta.persistence.jdbc.user" value=""/>
<property name="jakarta.persistence.jdbc.password" value=""/>
<property name="jakarta.persistence.jdbc.url" value="jdbc:h2:mem:;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'classpath:/classicmodels.sql'"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
</properties>
</persistence-unit>

</persistence>
109 changes: 109 additions & 0 deletions hibernate7/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate-parent</artifactId>
<version>2.20.0-SNAPSHOT</version>
</parent>
<artifactId>jackson-datatype-hibernate7</artifactId>
<name>Jackson-datatype-hibernate7</name>
<packaging>bundle</packaging>
<description>Add-on module for Jackson (https://github.com/FasterXML/jackson) to support
Hibernate (https://hibernate.org/) version 7.x with Jakarta data types.
</description>
<url>https://github.com/FasterXML/jackson-datatype-hibernate</url>
<properties>
<!-- Generate PackageVersion.java into this directory. -->
<packageVersion.dir>com/fasterxml/jackson/datatype/hibernate7</packageVersion.dir>
<packageVersion.package>${project.groupId}.hibernate7</packageVersion.package>
<!-- Hibernate with Jakarta Persistence 3.0 -->
<hibernate.version>7.0.3.Final</hibernate.version>
<osgi.export>${project.groupId}.hibernate7</osgi.export>
</properties>

<dependencies>
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
<version>2.0.1</version>
</dependency>

<!-- what would be the best scope to use here? -->
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<scope>provided</scope>
</dependency>

<!-- and for some contributed tests Mockito -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<!-- Inherited from oss-base. Generate PackageVersion.java.-->
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
</plugin>
<!-- 29-Apr-2025, tatu: SBOM generation [JSTEP-14] -->
<plugin>
<groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<jvmVersion>11</jvmVersion>
</configuration>
</plugin>
<!-- 05-Jul-2020, tatu: Add generation of Gradle Module Metadata -->
<!-- 28-Feb-2025, jjohannes: Apply plugin last as it has to be the last of all 'package phase' plugins -->
<plugin>
<groupId>org.gradlex</groupId>
<artifactId>gradle-module-metadata-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Loading
Loading