Joaquín Reñé
2025-05-27 89b1c533d1b48b8b339b9c74a59c2ce73e6431af
securis/src/main/java/net/curisit/securis/db/common/PersistentEnumUserType.java
....@@ -7,7 +7,7 @@
77 import java.sql.Types;
88
99 import org.hibernate.HibernateException;
10
-import org.hibernate.engine.spi.SessionImplementor;
10
+import org.hibernate.engine.spi.SharedSessionContractImplementor;
1111 import org.hibernate.usertype.UserType;
1212
1313 public abstract class PersistentEnumUserType<T extends CodedEnum> implements UserType {
....@@ -58,7 +58,8 @@
5858 }
5959
6060 @Override
61
- public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
61
+ public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner)
62
+ throws HibernateException, SQLException {
6263 String code = rs.getString(names[0]);
6364 for (CodedEnum en : returnedClass().getEnumConstants()) {
6465 if (en.getCode().equals(code)) {
....@@ -69,8 +70,13 @@
6970 }
7071
7172 @Override
72
- public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
73
- st.setString(index, value == null ? null : ((CodedEnum) value).getCode());
73
+ public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session)
74
+ throws HibernateException, SQLException {
75
+ if (value == null) {
76
+ st.setNull(index, java.sql.Types.VARCHAR);
77
+ } else {
78
+ st.setString(index, ((CodedEnum) value).getCode());
79
+ }
7480 }
7581
7682 }