Skip to content

Commit 4667f70

Browse files
authored
Merge branch '2.x' into hibernate7
2 parents a96e028 + 3217e37 commit 4667f70

File tree

3 files changed

+11
-42
lines changed

3 files changed

+11
-42
lines changed

hibernate6/src/main/java/com/fasterxml/jackson/datatype/hibernate6/Hibernate6ProxySerializer.java

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import org.hibernate.engine.spi.Mapping;
1010
import org.hibernate.engine.spi.SessionFactoryImplementor;
11-
import org.hibernate.engine.spi.SessionImplementor;
11+
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1212
import org.hibernate.proxy.HibernateProxy;
1313
import org.hibernate.proxy.LazyInitializer;
1414
import org.hibernate.proxy.pojo.BasicLazyInitializer;
@@ -249,6 +249,7 @@ private String getIdentifierPropertyName(final LazyInitializer init) {
249249
if (_mapping != null) {
250250
idName = _mapping.getIdentifierPropertyName(init.getEntityName());
251251
} else {
252+
// no unit tests rely on this next call and Hibernate 7 does not support it
252253
idName = ProxySessionReader.getIdentifierPropertyName(init);
253254
if (idName == null) {
254255
idName = ProxyReader.getIdentifierPropertyName(init);
@@ -301,47 +302,13 @@ static String getIdentifierPropertyName(LazyInitializer init) {
301302
}
302303
}
303304

304-
/**
305-
* Hibernate 5.2 broke abi compatibility of org.hibernate.proxy.LazyInitializer.getSession()
306-
* The api contract changed
307-
* from org.hibernate.proxy.LazyInitializer.getSession()Lorg.hibernate.engine.spi.SessionImplementor;
308-
* to org.hibernate.proxy.LazyInitializer.getSession()Lorg.hibernate.engine.spi.SharedSessionContractImplementor
309-
*
310-
* On hibernate 5.2 the interface SessionImplementor extends SharedSessionContractImplementor.
311-
* And an instance of org.hibernate.internal.SessionImpl is returned from getSession().
312-
*/
313305
protected static class ProxySessionReader {
314-
315-
/**
316-
* The getSession method must be executed using reflection for compatibility purpose.
317-
* For efficiency keep the method cached.
318-
*/
319-
protected static final Method lazyInitializerGetSessionMethod;
320-
321-
static {
322-
try {
323-
lazyInitializerGetSessionMethod = LazyInitializer.class.getMethod("getSession");
324-
} catch (Exception e) {
325-
// should never happen: the class and method exists in all versions of hibernate 5
326-
throw new RuntimeException(e);
327-
}
328-
}
329-
306+
330307
static String getIdentifierPropertyName(LazyInitializer init) {
331-
final Object session;
332-
try{
333-
session = lazyInitializerGetSessionMethod.invoke(init);
334-
} catch (Exception e) {
335-
// Should never happen
336-
throw new RuntimeException(e);
337-
}
338-
if(session instanceof SessionImplementor){
339-
SessionFactoryImplementor factory = ((SessionImplementor)session).getFactory();
340-
return factory.getIdentifierPropertyName(init.getEntityName());
341-
}else if (session != null) {
342-
// Should never happen: session should be an instance of org.hibernate.internal.SessionImpl
343-
// factory = session.getClass().getMethod("getFactory").invoke(session);
344-
throw new RuntimeException("Session is not instance of SessionImplementor");
308+
final SharedSessionContractImplementor session = init.getSession();
309+
if (session != null) {
310+
SessionFactoryImplementor factory = session.getFactory();
311+
return factory.getIdentifierPropertyName(init.getEntityName());
345312
}
346313
return null;
347314
}

hibernate6/src/main/java/com/fasterxml/jackson/datatype/hibernate6/PersistentCollectionSerializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ private Session openTemporarySessionForLoading(PersistentCollection coll) {
307307
session.setHibernateFlushMode(FlushMode.MANUAL);
308308

309309
persistenceContext.addUninitializedDetachedCollection(
310-
((SessionFactoryImplementor) _sessionFactory).getMetamodel().collectionPersister(coll.getRole()),
311-
coll
310+
((SessionFactoryImplementor) _sessionFactory).getMappingMetamodel().getCollectionDescriptor(coll.getRole()),
311+
coll
312312
);
313313

314314
return session;

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Project: jackson-datatype-hibernate
66

77
2.20.0 (not yet released)
88

9+
#186: Update hibernate 6 code to avoid deprecated code
10+
(fixed by @pjfanning)
911
- Generate SBOMs [JSTEP-14]
1012

1113
2.19.1 (13-Jun-2025)

0 commit comments

Comments
 (0)