Skip to content

Commit

Permalink
Fix #86
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 11, 2016
1 parent e6fdbba commit f64b7d7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hibernate5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Hibernate (http://hibernate.org) version 5.x data types.
<packageVersion.dir>com/fasterxml/jackson/datatype/hibernate5</packageVersion.dir>
<packageVersion.package>${project.groupId}.hibernate5</packageVersion.package>
<!-- Hibernate with JPA 2.0 -->
<hibernate.version>5.0.6.Final</hibernate.version>
<hibernate.version>5.1.0.Final</hibernate.version>
<surefire.version>2.12</surefire.version>
<osgi.export>${project.groupId}.hibernate5</osgi.export>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import javax.persistence.Transient;

import org.hibernate.bytecode.internal.javassist.FieldHandler;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
Expand All @@ -17,7 +15,7 @@
public class HibernateAnnotationIntrospector extends AnnotationIntrospector
{
private static final long serialVersionUID = 1L;

/**
* Whether we should check for existence of @Transient or not.
* Default value is 'true'.
Expand Down Expand Up @@ -78,10 +76,37 @@ public Boolean isIgnorableType(AnnotatedClass ac)
* of `FieldHandled`. Not sure if it works without test (alas, none provided),
* but will try our best -- problem is, if it'
*/
// ... could we avoid direct class reference?
if (FieldHandler.class.isAssignableFrom(ac.getAnnotated())) {
return Boolean.TRUE;
// 11-Feb-2016, tatu: As per [datatype-hibernate#86] must use indirection. Sigh.
Class<?> handlerClass = FieldHandlerChecker.instance.getHandlerClass();
if (handlerClass != null) {
if (handlerClass.isAssignableFrom(ac.getAnnotated())) {
return Boolean.TRUE;
}
}
return null;
}

/**
* Helper class used to encapsulate detection of <code>FieldHandler</code>; class
* that was part of Hibernate from 4.0 until 5.0, but removed from 5.1.
*/
final static class FieldHandlerChecker {
private final static String FIELD_HANDLER_INTERFACE = "org.hibernate.bytecode.internal.javassist.FieldHandler";

private final Class<?> _handlerClass;

public final static FieldHandlerChecker instance = new FieldHandlerChecker();

public FieldHandlerChecker() {
Class<?> cls = null;
try {
cls = Class.forName(FIELD_HANDLER_INTERFACE);
} catch (Throwable t) { }
_handlerClass = cls;
}

public Class<?> getHandlerClass() {
return _handlerClass;
}
}
}

0 comments on commit f64b7d7

Please sign in to comment.