Skip to content

Commit 0f5026c

Browse files
committed
Fixed #102 as per suggestions on issue
1 parent 9a29379 commit 0f5026c

File tree

4 files changed

+28
-60
lines changed

4 files changed

+28
-60
lines changed

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

+7-44
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ protected Object findLazyValue(PersistentCollection coll) {
310310
return null;
311311
}
312312
if (_sessionFactory != null) {
313+
// 08-Feb-2017, tatu: and not closing this is not problematic... ?
313314
Session session = openTemporarySessionForLoading(coll);
314315
initializeCollection(coll, session);
315316
}
@@ -423,52 +424,14 @@ private Object convertToSet(Set<?> value) {
423424
}
424425

425426
protected static class SessionReader {
426-
427-
/**
428-
* Return changed from org.hibernate.resource.transaction.TransactionCoordinator
429-
* to org.hibernate.resource.transaction.spi.TransactionCoordinator
430-
*/
431-
protected static final Method getTransactionCoordinatorMethod;
432-
/**
433-
* Return changed from org.hibernate.resource.transaction.TransactionCoordinatorBuilder
434-
* to org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder
435-
*/
436-
protected static final Method getTransactionCoordinatorBuilderMethod;
437-
/**
438-
* Class changed from org.hibernate.resource.transaction.TransactionCoordinatorBuilder
439-
* to org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder
440-
*/
441-
protected static final Method isJtaMethod;
442-
443-
static {
444-
try {
445-
getTransactionCoordinatorMethod = SessionImplementor.class.getMethod("getTransactionCoordinator");
446-
} catch (Exception e) {
447-
// should never happen: the class and method exists in all versions of hibernate 5
448-
throw new RuntimeException(e);
449-
}
450-
try{
451-
getTransactionCoordinatorBuilderMethod = Hibernate5Version.getTransactionCoordinatorClass().getMethod("getTransactionCoordinatorBuilder");
452-
} catch (Exception e) {
453-
// should never happen
454-
throw new RuntimeException(e);
455-
}
456-
try{
457-
isJtaMethod = Hibernate5Version.getTransactionCoordinatorClass().getMethod("isJta");
458-
} catch (Exception e) {
459-
// should never happen
460-
throw new RuntimeException(e);
461-
}
462-
}
463-
464427
public static boolean isJTA(Session session) {
465428
try {
466-
Object transactionCoordinator = getTransactionCoordinatorMethod.invoke(session);
467-
Object transactionCoordinatorBuilder = getTransactionCoordinatorBuilderMethod.invoke(transactionCoordinator);
468-
return (boolean) isJtaMethod.invoke(transactionCoordinatorBuilder);
469-
} catch (Exception e) {
470-
// Should never happen
471-
throw new RuntimeException(e);
429+
EntityManager em = (EntityManager) session;
430+
em.getTransaction();
431+
return false;
432+
} catch (IllegalStateException e) {
433+
// EntityManager is required to throw an IllegalStateException if it's JTA-managed
434+
return true;
472435
}
473436
}
474437
}

hibernate5_2-test/pom.xml

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
<parent>
44
<groupId>com.fasterxml.jackson.datatype</groupId>
55
<artifactId>jackson-datatype-hibernate-parent</artifactId>
6-
<version>2.8.6-SNAPSHOT</version>
6+
<version>2.8.7-SNAPSHOT</version>
77
</parent>
88
<artifactId>jackson-datatype-hibernate5_2-test</artifactId>
99
<dependencies>
10-
<dependency>
11-
<groupId>com.fasterxml.jackson.datatype</groupId>
12-
<artifactId>jackson-datatype-hibernate5</artifactId>
13-
<version>2.8.6-SNAPSHOT</version>
14-
<scope>test</scope>
15-
</dependency>
16-
<dependency>
17-
<groupId>com.fasterxml.jackson.datatype</groupId>
18-
<artifactId>jackson-datatype-hibernate5</artifactId>
19-
<version>2.8.6-SNAPSHOT</version>
20-
<type>test-jar</type>
21-
<scope>test</scope>
22-
</dependency>
10+
<dependency>
11+
<groupId>com.fasterxml.jackson.datatype</groupId>
12+
<artifactId>jackson-datatype-hibernate5</artifactId>
13+
<version>${project.version}</version>
14+
<scope>test</scope>
15+
</dependency>
16+
<dependency>
17+
<groupId>com.fasterxml.jackson.datatype</groupId>
18+
<artifactId>jackson-datatype-hibernate5</artifactId>
19+
<version>${project.version}</version>
20+
<type>test-jar</type>
21+
<scope>test</scope>
22+
</dependency>
2323
<dependency>
2424
<groupId>org.hibernate</groupId>
2525
<artifactId>hibernate-core</artifactId>
26-
<version>5.2.0.Final</version>
26+
<version>5.2.6.Final</version>
2727
<scope>provided</scope>
2828
</dependency>
2929

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<module>hibernate4</module>
1919
<module>hibernate5</module>
2020
<!-- temp, to get release out
21-
<module>hibernate5_2-test</module>
2221
-->
22+
<module>hibernate5_2-test</module>
2323
</modules>
2424

2525
<url>https://github.com/FasterXML/jackson-datatype-hibernate</url>

release-notes/VERSION

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-datatype-hibernate
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.8.7 (not yet released)
8+
9+
#102: 2.8.6 NoSuchMethodException with Hibernate 5.2
10+
(reported by Jordan G)
11+
712
2.8.6 (12-Jan-2017)
813

914
#92: Add support for Hibernate 5.2

0 commit comments

Comments
 (0)