datapublica / hibernate-pg-json

Provide json/jsonb mapping for hibernate
MIT License
17 stars 3 forks source link

Needs update to support hibernate 5.2 #1

Open Ramblurr opened 7 years ago

Ramblurr commented 7 years ago

This little library has served us great the past year, but now with hibernate 5.2 it is no longer working.

It needs just this little patch:

diff --git a/src/main/java/com/datapublica/pg/types/JsonType.java b/src/main/java/com/datapublica/pg/types/JsonType.java
index b6612c1..2baf0a9 100644
--- a/src/main/java/com/datapublica/pg/types/JsonType.java
+++ b/src/main/java/com/datapublica/pg/types/JsonType.java
@@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.ObjectReader;
 import com.fasterxml.jackson.databind.ObjectWriter;
 import com.fasterxml.jackson.databind.type.SimpleType;
 import org.hibernate.HibernateException;
-import org.hibernate.engine.spi.SessionImplementor;
+import org.hibernate.engine.spi.SharedSessionContractImplementor;
 import org.hibernate.usertype.UserType;
 import org.postgresql.util.PGobject;

@@ -73,8 +73,7 @@ public class JsonType implements UserType {
     public boolean isMutable() {
         return true;
     }
-
-    public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
+    public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
         if (value == null) {
             st.setObject(index, null);
             return;
@@ -85,7 +84,7 @@ public class JsonType implements UserType {
         st.setObject(index, pg);
     }

-    public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
+    public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException {
         final Object result = rs.getObject(names[0]);
         if (!rs.wasNull()) {
             String content;

The problem is that this makes the library not work any longer with hibernate < 5.2, which is undesirable.

@WydD I don't suppose you know how to solve this dilemma and have the inclination to do so?

WydD commented 7 years ago

First of all I'm glad this piece of code is of use :)

As for the rest, well that's a bummer... let me see if I have a way to hack this. Thanks for letting me know.

WydD commented 7 years ago

I tested this one with 5.0.9 and it seems to work and it compiles with 5.2.4. This is hacky (because it relies on lazy class loading) but it should work