Skip to content

Commit f64b7d7

Browse files
committed
Fix #86
1 parent e6fdbba commit f64b7d7

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

hibernate5/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Hibernate (http://hibernate.org) version 5.x data types.
1717
<packageVersion.dir>com/fasterxml/jackson/datatype/hibernate5</packageVersion.dir>
1818
<packageVersion.package>${project.groupId}.hibernate5</packageVersion.package>
1919
<!-- Hibernate with JPA 2.0 -->
20-
<hibernate.version>5.0.6.Final</hibernate.version>
20+
<hibernate.version>5.1.0.Final</hibernate.version>
2121
<surefire.version>2.12</surefire.version>
2222
<osgi.export>${project.groupId}.hibernate5</osgi.export>
2323
</properties>

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import javax.persistence.Transient;
44

5-
import org.hibernate.bytecode.internal.javassist.FieldHandler;
6-
75
import com.fasterxml.jackson.core.Version;
86
import com.fasterxml.jackson.databind.AnnotationIntrospector;
97
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
@@ -17,7 +15,7 @@
1715
public class HibernateAnnotationIntrospector extends AnnotationIntrospector
1816
{
1917
private static final long serialVersionUID = 1L;
20-
18+
2119
/**
2220
* Whether we should check for existence of @Transient or not.
2321
* Default value is 'true'.
@@ -78,10 +76,37 @@ public Boolean isIgnorableType(AnnotatedClass ac)
7876
* of `FieldHandled`. Not sure if it works without test (alas, none provided),
7977
* but will try our best -- problem is, if it'
8078
*/
81-
// ... could we avoid direct class reference?
82-
if (FieldHandler.class.isAssignableFrom(ac.getAnnotated())) {
83-
return Boolean.TRUE;
79+
// 11-Feb-2016, tatu: As per [datatype-hibernate#86] must use indirection. Sigh.
80+
Class<?> handlerClass = FieldHandlerChecker.instance.getHandlerClass();
81+
if (handlerClass != null) {
82+
if (handlerClass.isAssignableFrom(ac.getAnnotated())) {
83+
return Boolean.TRUE;
84+
}
8485
}
8586
return null;
8687
}
88+
89+
/**
90+
* Helper class used to encapsulate detection of <code>FieldHandler</code>; class
91+
* that was part of Hibernate from 4.0 until 5.0, but removed from 5.1.
92+
*/
93+
final static class FieldHandlerChecker {
94+
private final static String FIELD_HANDLER_INTERFACE = "org.hibernate.bytecode.internal.javassist.FieldHandler";
95+
96+
private final Class<?> _handlerClass;
97+
98+
public final static FieldHandlerChecker instance = new FieldHandlerChecker();
99+
100+
public FieldHandlerChecker() {
101+
Class<?> cls = null;
102+
try {
103+
cls = Class.forName(FIELD_HANDLER_INTERFACE);
104+
} catch (Throwable t) { }
105+
_handlerClass = cls;
106+
}
107+
108+
public Class<?> getHandlerClass() {
109+
return _handlerClass;
110+
}
111+
}
87112
}

0 commit comments

Comments
 (0)