-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for hibernate 5 #12
base: master
Are you sure you want to change the base?
Changes from 4 commits
d9bb4f2
1a475d3
70609e6
6ebe6e2
b59d99a
5e5a8f0
1995301
7a73ae6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
# install postgresql, wait for it to start and then create test database | ||
|
||
set -x | ||
|
||
sudo apt-get update -y | ||
sudo apt-get install -y postgresql-9.3 | ||
sudo sh -c 'echo "host all all localhost trust" > /etc/postgresql/9.3/main/pg_hba.conf' | ||
sudo sh -c 'echo "local all all trust" >> /etc/postgresql/9.3/main/pg_hba.conf' | ||
sudo service postgresql start | ||
until runuser -l postgres -c 'pg_isready' 2>/dev/null; do | ||
>&2 echo "Postgres is unavailable - sleeping for 2 seconds" | ||
sleep 2s | ||
done | ||
psql -c 'create database nativejson;' -U postgres |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,17 @@ | |
*/ | ||
package com.marvinformatics.hibernate.json; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
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.DynamicParameterizedType; | ||
import org.hibernate.usertype.UserType; | ||
import org.postgresql.util.PGobject; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.sql.PreparedStatement; | ||
|
@@ -23,17 +34,6 @@ | |
import java.sql.Types; | ||
import java.util.Properties; | ||
|
||
import org.hibernate.HibernateException; | ||
import org.hibernate.engine.spi.SessionImplementor; | ||
import org.hibernate.usertype.DynamicParameterizedType; | ||
import org.hibernate.usertype.UserType; | ||
import org.postgresql.util.PGobject; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.type.SimpleType; | ||
|
||
/** | ||
* Define a Jackson Serializer/Deserializer use to persist | ||
* | ||
|
@@ -68,7 +68,6 @@ public boolean isMutable() { | |
return true; | ||
} | ||
|
||
@Override | ||
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { | ||
PGobject dataObject = new PGobject(); | ||
dataObject.setType("json"); | ||
|
@@ -79,7 +78,14 @@ public void nullSafeSet(PreparedStatement st, Object value, int index, SessionIm | |
st.setObject(index, dataObject); | ||
} | ||
|
||
@Override | ||
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { | ||
return nullSafeGet(rs, names, (SessionImplementor) session, owner); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this cast is either safe nor necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right. I blindly copied the fix from my other project, which has jsonb working with hibernate using sprint boot 2.0.1. ill update this. |
||
} | ||
|
||
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { | ||
nullSafeSet(st, value, index, (SessionImplementor) session); | ||
} | ||
|
||
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { | ||
Object result = rs.getObject(names[0]); | ||
if (result instanceof PGobject) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this method is no longer part of the implementation, I think it's safe to take it out.