From 63b94469328427ee6cca96006d6707a8f6b3298b Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Wed, 3 Jan 2024 15:52:04 +0100
Subject: [PATCH] Non-functioning commit of Hibernate upgrade adaptations

---
 pom.xml                                       |   1 -
 .../nibio/vips/logic/entity/CropCategory.java |   7 +-
 .../no/nibio/vips/logic/entity/CropPest.java  |   7 +-
 .../logic/entity/ForecastConfiguration.java   |  10 +-
 .../no/nibio/vips/logic/entity/Message.java   |   8 +-
 .../nibio/vips/logic/entity/Observation.java  |   8 +-
 .../nibio/vips/logic/entity/UserUuidPK.java   |   1 -
 ...ForecastEventNotificationSubscription.java |   9 +-
 .../MessageNotificationSubscription.java      |  10 +-
 .../ObservationNotificationSubscription.java  |   7 +-
 .../logic/messaging/UniversalMessage.java     |  10 +-
 .../vips/logic/util/IntegerArrayUserType.java | 215 ++++--------------
 .../logic/util/JsonPostgreSQLDialect.java     |  35 ---
 .../vips/logic/util/StringJsonUserType.java   | 169 ++++----------
 .../ObservationDataSchema.java                |  11 +-
 src/main/resources/META-INF/persistence.xml   |   6 +-
 16 files changed, 112 insertions(+), 402 deletions(-)
 delete mode 100755 src/main/java/no/nibio/vips/logic/util/JsonPostgreSQLDialect.java

diff --git a/pom.xml b/pom.xml
index 22b57e70..dc89bad7 100755
--- a/pom.xml
+++ b/pom.xml
@@ -171,7 +171,6 @@
                 </exclusion>
             </exclusions>
         </dependency>
-
         <dependency>
             <groupId>org.postgresql</groupId>
             <artifactId>postgresql</artifactId>
diff --git a/src/main/java/no/nibio/vips/logic/entity/CropCategory.java b/src/main/java/no/nibio/vips/logic/entity/CropCategory.java
index 43cc4587..c1c588f7 100755
--- a/src/main/java/no/nibio/vips/logic/entity/CropCategory.java
+++ b/src/main/java/no/nibio/vips/logic/entity/CropCategory.java
@@ -26,6 +26,7 @@ import java.util.Set;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
+import javax.persistence.Convert;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Id;
@@ -37,9 +38,6 @@ import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Size;
 import javax.xml.bind.annotation.XmlRootElement;
 import no.nibio.vips.logic.util.IntegerArrayUserType;
-import org.hibernate.annotations.Type;
-import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
 
 /**
  * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
@@ -48,7 +46,6 @@ import org.hibernate.annotations.TypeDefs;
 @Entity
 @Table(name = "crop_category")
 @XmlRootElement
-@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
 @NamedQueries({
     @NamedQuery(name = "CropCategory.findAll", query = "SELECT c FROM CropCategory c"),
     @NamedQuery(name = "CropCategory.findByCropCategoryId", query = "SELECT c FROM CropCategory c WHERE c.cropCategoryId = :cropCategoryId"),
@@ -70,7 +67,7 @@ public class CropCategory implements Serializable {
     private String defaultName;
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "cropCategoryId", fetch = FetchType.EAGER)
     private Set<CropCategoryLocal> cropCategoryLocalSet;
-    @Type(type = "IntegerArray")
+    @Convert(converter = IntegerArrayUserType.class)
     @Column(name = "crop_organism_ids")
     private Integer[] cropOrganismIds;
     @Column(name = "organization_id")
diff --git a/src/main/java/no/nibio/vips/logic/entity/CropPest.java b/src/main/java/no/nibio/vips/logic/entity/CropPest.java
index 0443494b..9ba62175 100755
--- a/src/main/java/no/nibio/vips/logic/entity/CropPest.java
+++ b/src/main/java/no/nibio/vips/logic/entity/CropPest.java
@@ -21,6 +21,7 @@ package no.nibio.vips.logic.entity;
 import java.io.Serializable;
 import javax.persistence.Basic;
 import javax.persistence.Column;
+import javax.persistence.Convert;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.NamedQueries;
@@ -29,9 +30,6 @@ import javax.persistence.Table;
 import javax.validation.constraints.NotNull;
 import javax.xml.bind.annotation.XmlRootElement;
 import no.nibio.vips.logic.util.IntegerArrayUserType;
-import org.hibernate.annotations.Type;
-import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
 
 /**
  * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
@@ -39,7 +37,6 @@ import org.hibernate.annotations.TypeDefs;
  */
 @Entity
 @Table(name = "crop_pest")
-@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
 @XmlRootElement
 @NamedQueries({
     @NamedQuery(name = "CropPest.findAll", query = "SELECT c FROM CropPest c"),
@@ -55,7 +52,7 @@ public class CropPest implements Serializable {
     @NotNull
     @Column(name = "crop_organism_id")
     private Integer cropOrganismId;
-    @Type(type = "IntegerArray")
+    @Convert(converter = IntegerArrayUserType.class)
     @Column(name = "pest_organism_ids")
     private Integer[] pestOrganismIds;
     @Column(name = "include_all_child_crops")
diff --git a/src/main/java/no/nibio/vips/logic/entity/ForecastConfiguration.java b/src/main/java/no/nibio/vips/logic/entity/ForecastConfiguration.java
index a17f2fba..57f09f87 100755
--- a/src/main/java/no/nibio/vips/logic/entity/ForecastConfiguration.java
+++ b/src/main/java/no/nibio/vips/logic/entity/ForecastConfiguration.java
@@ -42,13 +42,10 @@ import javax.xml.bind.annotation.XmlTransient;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import java.util.List;
 import java.util.TimeZone;
+import javax.persistence.Convert;
 import javax.persistence.Transient;
 import no.nibio.vips.logic.util.IntegerArrayUserType;
 import no.nibio.vips.util.WeatherUtil;
-import org.hibernate.annotations.Type;
-import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
-
 /**
  * @copyright 2014-2016 <a href="http://www.nibio.no/">NIBIO</a>
  * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
@@ -56,7 +53,6 @@ import org.hibernate.annotations.TypeDefs;
 @Entity
 @Table(name = "forecast_configuration")
 @XmlRootElement
-@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
 @NamedQueries({
     @NamedQuery(name = "ForecastConfiguration.findAll", query = "SELECT f FROM ForecastConfiguration f WHERE f.isPrivate = FALSE"),
     @NamedQuery(name = "ForecastConfiguration.findByForecastConfigurationId", query = "SELECT f FROM ForecastConfiguration f WHERE f.forecastConfigurationId = :forecastConfigurationId"),
@@ -85,6 +81,8 @@ import org.hibernate.annotations.TypeDefs;
     @NamedQuery(name = "ForecastConfiguration.findByModelIdAndYear", query = "SELECT f FROM ForecastConfiguration f WHERE f.modelId = :modelId AND YEAR(f.dateStart) <= :year AND YEAR(f.dateEnd) >= :year AND f.isPrivate = FALSE")
 })
 public class ForecastConfiguration implements Serializable, Comparable {
+    
+    
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "forecastConfiguration", fetch = FetchType.EAGER)
     private Set<ForecastModelConfiguration> forecastModelConfigurationSet;
     private static final long serialVersionUID = 1L;
@@ -124,7 +122,7 @@ public class ForecastConfiguration implements Serializable, Comparable {
     @Column(name = "is_private")
     private Boolean isPrivate;
     
-    @Type(type = "IntegerArray")
+    @Convert(converter = IntegerArrayUserType.class)
     @Column(name = "grid_weather_station_point_of_interest_ids")
     private Integer[] gridWeatherStationPointOfInterestIds;
     
diff --git a/src/main/java/no/nibio/vips/logic/entity/Message.java b/src/main/java/no/nibio/vips/logic/entity/Message.java
index 1bd92c60..72cfa793 100755
--- a/src/main/java/no/nibio/vips/logic/entity/Message.java
+++ b/src/main/java/no/nibio/vips/logic/entity/Message.java
@@ -27,6 +27,7 @@ import java.util.Set;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
+import javax.persistence.Convert;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
@@ -44,9 +45,7 @@ import javax.persistence.TemporalType;
 import javax.persistence.Transient;
 import javax.xml.bind.annotation.XmlRootElement;
 import no.nibio.vips.logic.util.IntegerArrayUserType;
-import org.hibernate.annotations.Type;
-import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
+
 
 /**
  * @copyright 2014 <a href="http://www.nibio.no/">NIBIO</a>
@@ -55,7 +54,6 @@ import org.hibernate.annotations.TypeDefs;
 @Entity
 @Table(name = "message")
 @XmlRootElement
-@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
 @NamedQueries({
     @NamedQuery(name = "Message.findAll", query = "SELECT m FROM Message m"),
     @NamedQuery(name = "Message.findByMessageId", query = "SELECT m FROM Message m WHERE m.messageId = :messageId"),
@@ -276,7 +274,7 @@ public class Message implements Serializable {
     /**
      * @return the cropCategoryIds
      */
-    @Type(type = "IntegerArray")
+    @Convert(converter = IntegerArrayUserType.class)
     @Column(name="crop_category_ids")
     public Integer[] getCropCategoryIds() {
         return cropCategoryIds;
diff --git a/src/main/java/no/nibio/vips/logic/entity/Observation.java b/src/main/java/no/nibio/vips/logic/entity/Observation.java
index 54fbc58b..f380af92 100755
--- a/src/main/java/no/nibio/vips/logic/entity/Observation.java
+++ b/src/main/java/no/nibio/vips/logic/entity/Observation.java
@@ -42,6 +42,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import javax.persistence.CascadeType;
+import javax.persistence.Convert;
 import javax.persistence.FetchType;
 import javax.persistence.OneToMany;
 import javax.validation.constraints.Size;
@@ -50,9 +51,7 @@ import no.nibio.vips.gis.GISUtil;
 import no.nibio.vips.logic.entity.rest.ObservationListItem;
 import no.nibio.vips.logic.util.StringJsonUserType;
 import no.nibio.vips.observationdata.ObservationDataSchema;
-import org.hibernate.annotations.Type;
-import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
+
 
 /**
  * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
@@ -61,7 +60,6 @@ import org.hibernate.annotations.TypeDefs;
 @Entity
 @Table(name = "observation")
 @XmlRootElement
-@TypeDefs( {@TypeDef( name= "StringJsonObject", typeClass = StringJsonUserType.class)})
 @NamedQueries({
     @NamedQuery(name = "Observation.findAll", query = "SELECT o FROM Observation o"),
     @NamedQuery(name = "Observation.findByObservationId", query = "SELECT o FROM Observation o WHERE o.observationId = :observationId"),
@@ -440,7 +438,7 @@ public class Observation implements Serializable, no.nibio.vips.observation.Obse
     /**
      * @return the observationData
      */
-    @Type(type = "StringJsonObject")
+    @Convert(converter = StringJsonUserType.class)
     @Column(name = "observation_data")
     @Override
     public String getObservationData() {
diff --git a/src/main/java/no/nibio/vips/logic/entity/UserUuidPK.java b/src/main/java/no/nibio/vips/logic/entity/UserUuidPK.java
index 9168cdfb..d48b5028 100755
--- a/src/main/java/no/nibio/vips/logic/entity/UserUuidPK.java
+++ b/src/main/java/no/nibio/vips/logic/entity/UserUuidPK.java
@@ -34,7 +34,6 @@ public class UserUuidPK implements Serializable {
     @Basic(optional = false)
     @NotNull
     @Column(name = "user_uuid")
-    @org.hibernate.annotations.Type(type="pg-uuid") // Ugly implementation specific hack
     private UUID userUuid;
     @Basic(optional = false)
     @NotNull
diff --git a/src/main/java/no/nibio/vips/logic/messaging/ForecastEventNotificationSubscription.java b/src/main/java/no/nibio/vips/logic/messaging/ForecastEventNotificationSubscription.java
index 157953ea..46d7b874 100755
--- a/src/main/java/no/nibio/vips/logic/messaging/ForecastEventNotificationSubscription.java
+++ b/src/main/java/no/nibio/vips/logic/messaging/ForecastEventNotificationSubscription.java
@@ -21,13 +21,11 @@ package no.nibio.vips.logic.messaging;
 import java.util.List;
 import javax.persistence.Basic;
 import javax.persistence.Column;
+import javax.persistence.Convert;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
 import no.nibio.vips.logic.util.IntegerArrayUserType;
-import org.hibernate.annotations.Type;
-import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
 
 /**
  * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
@@ -35,7 +33,6 @@ import org.hibernate.annotations.TypeDefs;
  */
 @Entity
 @Table(name = "forecast_event_notification_subscription", schema = "messaging")
-@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
 public class ForecastEventNotificationSubscription {
 
     @Id
@@ -46,11 +43,11 @@ public class ForecastEventNotificationSubscription {
     @Column(name = "universal_message_format_id")
     private Integer universalMessageFormatId;
     
-    @Type(type = "IntegerArray")
+    @Convert(converter = IntegerArrayUserType.class)
     @Column(name = "weather_station_ids")
     private Integer[] weatherStationIds;
     
-    @Type(type = "IntegerArray")
+    @Convert(converter = IntegerArrayUserType.class)
     @Column(name = "crop_category_ids")
     private Integer[] cropCategoryIds;
 
diff --git a/src/main/java/no/nibio/vips/logic/messaging/MessageNotificationSubscription.java b/src/main/java/no/nibio/vips/logic/messaging/MessageNotificationSubscription.java
index 2231f3b1..ee56bbd5 100755
--- a/src/main/java/no/nibio/vips/logic/messaging/MessageNotificationSubscription.java
+++ b/src/main/java/no/nibio/vips/logic/messaging/MessageNotificationSubscription.java
@@ -22,13 +22,12 @@ import java.io.Serializable;
 import java.util.List;
 import javax.persistence.Basic;
 import javax.persistence.Column;
+import javax.persistence.Convert;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
 import no.nibio.vips.logic.util.IntegerArrayUserType;
-import org.hibernate.annotations.Type;
-import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
+
 
 /**
  * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
@@ -36,7 +35,6 @@ import org.hibernate.annotations.TypeDefs;
  */
 @Entity
 @Table(name = "message_notification_subscription", schema = "messaging")
-@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
 public class MessageNotificationSubscription implements Serializable {
 
     @Id
@@ -47,11 +45,11 @@ public class MessageNotificationSubscription implements Serializable {
     @Column(name = "universal_message_format_id")
     private Integer universalMessageFormatId;
     
-    @Type(type = "IntegerArray")
+    @Convert(converter = IntegerArrayUserType.class)
     @Column(name = "message_tag_ids")
     private Integer[] messageTagIds;
     
-    @Type(type = "IntegerArray")
+    @Convert(converter = IntegerArrayUserType.class)
     @Column(name = "crop_category_ids")
     private Integer[] cropCategoryIds;
 
diff --git a/src/main/java/no/nibio/vips/logic/messaging/ObservationNotificationSubscription.java b/src/main/java/no/nibio/vips/logic/messaging/ObservationNotificationSubscription.java
index 7df24d95..f4e41029 100755
--- a/src/main/java/no/nibio/vips/logic/messaging/ObservationNotificationSubscription.java
+++ b/src/main/java/no/nibio/vips/logic/messaging/ObservationNotificationSubscription.java
@@ -22,13 +22,11 @@ import java.io.Serializable;
 import java.util.List;
 import javax.persistence.Basic;
 import javax.persistence.Column;
+import javax.persistence.Convert;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
 import no.nibio.vips.logic.util.IntegerArrayUserType;
-import org.hibernate.annotations.Type;
-import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
 
 /**
  * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
@@ -36,7 +34,6 @@ import org.hibernate.annotations.TypeDefs;
  */
 @Entity
 @Table(name = "observation_notification_subscription", schema = "messaging")
-@TypeDefs( {@TypeDef( name= "IntegerArray", typeClass = IntegerArrayUserType.class)})
 public class ObservationNotificationSubscription implements Serializable {
 
     @Id
@@ -47,7 +44,7 @@ public class ObservationNotificationSubscription implements Serializable {
     @Column(name = "universal_message_format_id")
     private Integer universalMessageFormatId;
     
-    @Type(type = "IntegerArray")
+    @Convert(converter = IntegerArrayUserType.class)
     @Column(name = "crop_category_ids")
     private Integer[] cropCategoryIds;
 
diff --git a/src/main/java/no/nibio/vips/logic/messaging/UniversalMessage.java b/src/main/java/no/nibio/vips/logic/messaging/UniversalMessage.java
index db8020bf..8b6e704e 100755
--- a/src/main/java/no/nibio/vips/logic/messaging/UniversalMessage.java
+++ b/src/main/java/no/nibio/vips/logic/messaging/UniversalMessage.java
@@ -46,10 +46,9 @@ import javax.persistence.Transient;
 import javax.xml.bind.annotation.XmlRootElement;
 
 import com.ibm.icu.util.ULocale;
+import javax.persistence.Convert;
 import no.nibio.vips.logic.util.StringJsonUserType;
-import org.hibernate.annotations.Type;
-import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
+
 
 /**
  * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
@@ -58,7 +57,6 @@ import org.hibernate.annotations.TypeDefs;
 @Entity
 @Table(name = "universal_message", schema = "messaging")
 @XmlRootElement
-@TypeDefs( {@TypeDef( name= "StringJsonObject", typeClass = StringJsonUserType.class)})
 @NamedQueries({
     @NamedQuery(name = "UniversalMessage.findAll", query = "SELECT u FROM UniversalMessage u"),
     @NamedQuery(name = "UniversalMessage.findByUniversalMessageId", query = "SELECT u FROM UniversalMessage u WHERE u.universalMessageId = :universalMessageId"),
@@ -76,11 +74,11 @@ public class UniversalMessage implements Serializable {
     //@Column(name = "distribution_list", columnDefinition = "json")
     //@Convert(converter = PostgresJSONStringConverter.class)
     // Documentation on StackOverflow: http://stackoverflow.com/questions/15974474/mapping-postgresql-json-column-to-hibernate-value-type
-    @Type(type = "StringJsonObject")
+    @Convert(converter = StringJsonUserType.class)
     @Column(name = "distribution_list")
     private String distributionList;
     
-    @Type(type = "StringJsonObject")
+    @Convert(converter = StringJsonUserType.class)
     @Column(name = "message_local_versions")
     private String messageLocalVersions;
     
diff --git a/src/main/java/no/nibio/vips/logic/util/IntegerArrayUserType.java b/src/main/java/no/nibio/vips/logic/util/IntegerArrayUserType.java
index 94ea3338..ef99793a 100755
--- a/src/main/java/no/nibio/vips/logic/util/IntegerArrayUserType.java
+++ b/src/main/java/no/nibio/vips/logic/util/IntegerArrayUserType.java
@@ -24,6 +24,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Types;
+import java.util.Arrays;
 import org.hibernate.HibernateException;
 import org.hibernate.engine.spi.SessionImplementor;
 import org.hibernate.engine.spi.SharedSessionContractImplementor;
@@ -35,206 +36,84 @@ import org.hibernate.usertype.UserType;
  * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
  */
 
-public class IntegerArrayUserType implements UserType {
+public class IntegerArrayUserType implements UserType<Integer[]> {
 
-    /**
-     * Return the SQL type codes for the columns mapped by this type. The
-     * codes are defined on <tt>java.sql.Types</tt>.
-     *
-     * @return int[] the typecodes
-     * @see java.sql.Types
-     */
-    @Override
-    public int[] sqlTypes() {
-        return new int[] { Types.ARRAY };
+    public IntegerArrayUserType()
+    {
+        super();
     }
-
     /**
      * The class returned by <tt>nullSafeGet()</tt>.
      *
      * @return Class
      */
     @Override
-    public Class returnedClass() {
+    public Class<Integer[]> returnedClass() {
         return Integer[].class;
     }
 
+
     /**
-     * Compare two instances of the class mapped by this type for persistence "equality".
-     * Equality of the persistent state.
+     * Are objects of this type mutable?
      *
-     * @param x
-     * @param y
      * @return boolean
      */
     @Override
-    public boolean equals(Object x, Object y) throws HibernateException {
-
-        if( x== null){
-
-            return y== null;
-        }
-
-        return x.equals( y);
+    public boolean isMutable() {
+        return true;
     }
 
-    /**
-     * Get a hashcode for the instance, consistent with persistence "equality"
-     */
+    
     @Override
-    public int hashCode(Object x) throws HibernateException {
-
-        return x.hashCode();
+    public int getSqlType() {
+        return Types.ARRAY;
     }
 
-    /**
-     * Retrieve an instance of the mapped class from a JDBC resultset. Implementors
-     * should handle possibility of null values.
-     *
-     * @param rs      a JDBC result set
-     * @param names   the column names
-     * @param session
-     * @param owner   the containing entity  @return Object
-     * @throws org.hibernate.HibernateException
-     *
-     * @throws java.sql.SQLException
-     */
-    //@Override
-    public Object nullSafeGet(
-            ResultSet rs, 
-            String[] names, 
-            SessionImplementor session, 
-            Object owner) throws HibernateException, SQLException {
-       if (rs.wasNull()) {
-        return null;
-    }
-
-       try
-       {
-        Integer[] array = (Integer[]) rs.getArray(names[0]).getArray();
-        return array;
-       }
-       catch(NullPointerException ex)
-       {
-           return new Integer[0];
-       }
-    }
+    @Override
+    public boolean equals(Integer[] x, Integer[] y) {
+        if( x== null){
 
-    /**
-     * Write an instance of the mapped class to a prepared statement. Implementors
-     * should handle possibility of null values. A multi-column type should be written
-     * to parameters starting from <tt>index</tt>.
-     *
-     * @param st      a JDBC prepared statement
-     * @param value   the object to write
-     * @param index   statement parameter index
-     * @param session
-     * @throws org.hibernate.HibernateException
-     *
-     * @throws java.sql.SQLException
-     */
-    //@Override
-    public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException {
-        if (value == null) {
-            st.setNull(index, Types.OTHER);
-            return;
+            return y== null;
         }
 
-        Integer[] castObject = (Integer[]) value;
-        Array array = session.connection().createArrayOf("integer", castObject); // The postgres array data type
-        st.setArray(index, array);
+        return x.equals( y);
     }
 
-    /**
-     * Return a deep copy of the persistent state, stopping at entities and at
-     * collections. It is not necessary to copy immutable objects, or null
-     * values, in which case it is safe to simply return the argument.
-     *
-     * @param value the object to be cloned, which may be null
-     * @return Object a copy
-     */
     @Override
-    public Object deepCopy(Object value) throws HibernateException {
-
-        return value;
+    public int hashCode(Integer[] j) {
+        return Arrays.hashCode(j);
     }
 
-    /**
-     * Are objects of this type mutable?
-     *
-     * @return boolean
-     */
     @Override
-    public boolean isMutable() {
-        return true;
-    }
+    public void nullSafeSet(PreparedStatement ps, Integer[] j, int i, SharedSessionContractImplementor ssci) throws SQLException {
+         if (j == null) {
+            ps.setNull(i, Types.OTHER);
+            return;
+        }
 
-    /**
-     * Transform the object into its cacheable representation. At the very least this
-     * method should perform a deep copy if the type is mutable. That may not be enough
-     * for some implementations, however; for example, associations must be cached as
-     * identifier values. (optional operation)
-     *
-     * @param value the object to be cached
-     * @return a cachable representation of the object
-     * @throws org.hibernate.HibernateException
-     *
-     */
-    @Override
-    public Serializable disassemble(Object value) throws HibernateException {
-        return (Integer[])this.deepCopy( value);
+        Integer[] castObject = (Integer[]) j;
+        Array array = ssci.getJdbcConnectionAccess().obtainConnection().createArrayOf("integer", castObject); // The postgres array data type
+        ps.setArray(i, array);
     }
 
-    /**
-     * Reconstruct an object from the cacheable representation. At the very least this
-     * method should perform a deep copy if the type is mutable. (optional operation)
-     *
-     * @param cached the object to be cached
-     * @param owner  the owner of the cached object
-     * @return a reconstructed object from the cachable representation
-     * @throws org.hibernate.HibernateException
-     *
-     */
     @Override
-    public Object assemble(Serializable cached, Object owner) throws HibernateException {
-        return this.deepCopy( cached);
+    public Integer[] deepCopy(Integer[] j) {
+        return j;
     }
 
-    /**
-     * During merge, replace the existing (target) value in the entity we are merging to
-     * with a new (original) value from the detached entity we are merging. For immutable
-     * objects, or null values, it is safe to simply return the first parameter. For
-     * mutable objects, it is safe to return a copy of the first parameter. For objects
-     * with component values, it might make sense to recursively replace component values.
-     *
-     * @param original the value from the detached entity being merged
-     * @param target   the value in the managed entity
-     * @return the value to be merged
-     */
     @Override
-    public Object replace(Object original, Object target, Object owner) throws HibernateException {
-        return original;
+    public Serializable disassemble(Integer[] j) {
+        throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
     }
 
-    /**
-     * Retrieve an instance of the mapped class from a JDBC resultset. Implementors
-     * should handle possibility of null values.
-     *
-     * @param rs      a JDBC result set
-     * @param strings   the column names
-     * @param ssci
-     * @throws org.hibernate.HibernateException
-     *
-     * @throws java.sql.SQLException
-     */
     @Override
-    public Object nullSafeGet(ResultSet rs, String[] strings, SharedSessionContractImplementor ssci, Object o) throws HibernateException, SQLException {
+    public Integer[] nullSafeGet(ResultSet rs, int i, SharedSessionContractImplementor ssci, Object o) throws SQLException {
         if (rs.wasNull()) {
             return null;
         }
         try
         {
-            Integer[] array = (Integer[]) rs.getArray(strings[0]).getArray();
+            Integer[] array = (Integer[]) rs.getArray(i).getArray();
             return array;
         }
         catch(NullPointerException ex)
@@ -243,30 +122,12 @@ public class IntegerArrayUserType implements UserType {
         }
     }
 
-    /**
-     * Write an instance of the mapped class to a prepared statement. Implementors
-     * should handle possibility of null values. A multi-column type should be written
-     * to parameters starting from <tt>index</tt>.
-     *
-     * @param ps      a JDBC prepared statement
-     * @param o   the object to write
-     * @param i   statement parameter index
-     * @param ssci
-     * @throws org.hibernate.HibernateException
-     *
-     * @throws java.sql.SQLException
-     */
     @Override
-    public void nullSafeSet(PreparedStatement ps, Object o, int i, SharedSessionContractImplementor ssci) throws HibernateException, SQLException {
-        if (o == null) {
-            ps.setNull(i, Types.OTHER);
-            return;
-        }
-
-        Integer[] castObject = (Integer[]) o;
-        Array array = ssci.connection().createArrayOf("integer", castObject); // The postgres array data type
-        ps.setArray(i, array);
+    public Integer[] assemble(Serializable srlzbl, Object o) {
+        throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
     }
 
+   
+
 
 }
diff --git a/src/main/java/no/nibio/vips/logic/util/JsonPostgreSQLDialect.java b/src/main/java/no/nibio/vips/logic/util/JsonPostgreSQLDialect.java
deleted file mode 100755
index 2e7dda6a..00000000
--- a/src/main/java/no/nibio/vips/logic/util/JsonPostgreSQLDialect.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2015 NIBIO <http://www.nibio.no/>. 
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-package no.nibio.vips.logic.util;
-
-import java.sql.Types;
-import org.hibernate.dialect.PostgreSQL9Dialect;
-
-/**
- * @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
- * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
- */
-public class JsonPostgreSQLDialect extends PostgreSQL9Dialect{
-    public JsonPostgreSQLDialect() {
-
-        super();
-
-        this.registerColumnType(Types.JAVA_OBJECT, "json");
-    }
-}
diff --git a/src/main/java/no/nibio/vips/logic/util/StringJsonUserType.java b/src/main/java/no/nibio/vips/logic/util/StringJsonUserType.java
index 1672d607..2b36426c 100755
--- a/src/main/java/no/nibio/vips/logic/util/StringJsonUserType.java
+++ b/src/main/java/no/nibio/vips/logic/util/StringJsonUserType.java
@@ -29,23 +29,13 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
 import org.hibernate.usertype.UserType;
 
 /**
- * @copyright 2015-2019 <a href="http://www.nibio.no/">NIBIO</a>
+ * @copyright 2015-2024 <a href="http://www.nibio.no/">NIBIO</a>
  * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
  */
 
-public class StringJsonUserType implements UserType {
+public class StringJsonUserType implements UserType<String> {
+
 
-    /**
-     * Return the SQL type codes for the columns mapped by this type. The
-     * codes are defined on <tt>java.sql.Types</tt>.
-     *
-     * @return int[] the typecodes
-     * @see java.sql.Types
-     */
-    @Override
-    public int[] sqlTypes() {
-        return new int[] { Types.JAVA_OBJECT};
-    }
 
     /**
      * The class returned by <tt>nullSafeGet()</tt>.
@@ -57,53 +47,7 @@ public class StringJsonUserType implements UserType {
         return String.class;
     }
 
-    /**
-     * Compare two instances of the class mapped by this type for persistence "equality".
-     * Equality of the persistent state.
-     *
-     * @param x
-     * @param y
-     * @return boolean
-     */
-    @Override
-    public boolean equals(Object x, Object y) throws HibernateException {
-
-        if( x== null){
-
-            return y== null;
-        }
-
-        return x.equals( y);
-    }
-
-    /**
-     * Get a hashcode for the instance, consistent with persistence "equality"
-     */
-    @Override
-    public int hashCode(Object x) throws HibernateException {
-
-        return x.hashCode();
-    }
 
-    /**
-     * Retrieve an instance of the mapped class from a JDBC resultset. Implementors
-     * should handle possibility of null values.
-     *
-     * @param rs      a JDBC result set
-     * @param names   the column names
-     * @param session
-     * @param owner   the containing entity  @return Object
-     * @throws org.hibernate.HibernateException
-     *
-     * @throws java.sql.SQLException
-     */
-    //@Override
-    public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
-        if(rs.getString(names[0]) == null){
-            return null;
-        }
-        return rs.getString(names[0]);
-    }
 
     /**
      * Write an instance of the mapped class to a prepared statement. Implementors
@@ -135,12 +79,12 @@ public class StringJsonUserType implements UserType {
      *
      * @param value the object to be cloned, which may be null
      * @return Object a copy
-     */
+     *
     @Override
     public Object deepCopy(Object value) throws HibernateException {
 
         return value;
-    }
+    }*/
 
     /**
      * Are objects of this type mutable?
@@ -152,95 +96,60 @@ public class StringJsonUserType implements UserType {
         return true;
     }
 
-    /**
-     * Transform the object into its cacheable representation. At the very least this
-     * method should perform a deep copy if the type is mutable. That may not be enough
-     * for some implementations, however; for example, associations must be cached as
-     * identifier values. (optional operation)
-     *
-     * @param value the object to be cached
-     * @return a cachable representation of the object
-     * @throws org.hibernate.HibernateException
-     *
-     */
     @Override
-    public Serializable disassemble(Object value) throws HibernateException {
-        return (String)this.deepCopy( value);
+    public int getSqlType() {
+        return Types.JAVA_OBJECT;
     }
 
-    /**
-     * Reconstruct an object from the cacheable representation. At the very least this
-     * method should perform a deep copy if the type is mutable. (optional operation)
-     *
-     * @param cached the object to be cached
-     * @param owner  the owner of the cached object
-     * @return a reconstructed object from the cachable representation
-     * @throws org.hibernate.HibernateException
-     *
-     */
     @Override
-    public Object assemble(Serializable cached, Object owner) throws HibernateException {
-        return this.deepCopy( cached);
+    public boolean equals(String x, String y) {
+        if( x== null){
+
+            return y== null;
+        }
+
+        return x.equals( y);
     }
 
-    /**
-     * During merge, replace the existing (target) value in the entity we are merging to
-     * with a new (original) value from the detached entity we are merging. For immutable
-     * objects, or null values, it is safe to simply return the first parameter. For
-     * mutable objects, it is safe to return a copy of the first parameter. For objects
-     * with component values, it might make sense to recursively replace component values.
-     *
-     * @param original the value from the detached entity being merged
-     * @param target   the value in the managed entity
-     * @return the value to be merged
-     */
     @Override
-    public Object replace(Object original, Object target, Object owner) throws HibernateException {
-        return original;
+    public int hashCode(String j) {
+        return j.hashCode();
     }
 
-    
-    /**
-     * Retrieve an instance of the mapped class from a JDBC resultset. Implementors
-     * should handle possibility of null values.
-     *
-     * @param rs      a JDBC result set
-     * @param strings   the column names
-     * @param ssci
-     * @throws org.hibernate.HibernateException
-     *
-     * @throws java.sql.SQLException
-     */
     @Override
-    public Object nullSafeGet(ResultSet rs, String[] strings, SharedSessionContractImplementor ssci, Object o) throws HibernateException, SQLException {
-        if(rs.getString(strings[0]) == null){
+    public String nullSafeGet(ResultSet rs, int i, SharedSessionContractImplementor ssci, Object o) throws SQLException {
+          if(rs.getString(i) == null){
             return null;
         }
-        return rs.getString(strings[0]);
+        return rs.getString(i);
     }
 
-    /**
-     * Write an instance of the mapped class to a prepared statement. Implementors
-     * should handle possibility of null values. A multi-column type should be written
-     * to parameters starting from <tt>index</tt>.
-     *
-     * @param ps      a JDBC prepared statement
-     * @param o   the object to write
-     * @param i   statement parameter index
-     * @param ssci
-     * @throws org.hibernate.HibernateException
-     *
-     * @throws java.sql.SQLException
-     */
     @Override
-    public void nullSafeSet(PreparedStatement ps, Object o, int i, SharedSessionContractImplementor ssci) throws HibernateException, SQLException {
-        if (o == null) {
+    public void nullSafeSet(PreparedStatement ps, String j, int i, SharedSessionContractImplementor ssci) throws SQLException {
+         if (j == null) {
             ps.setNull(i, Types.OTHER);
             return;
         }
 
-        ps.setObject(i, o, Types.OTHER);
+         ps.setString(i, j);
     }
 
+    @Override
+    public String deepCopy(String j) {
+        return j;
+    }
+
+    @Override
+    public Serializable disassemble(String j) {
+        throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
+    }
+
+    @Override
+    public String assemble(Serializable srlzbl, Object o) {
+        throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
+    }
+
+   
+
 
 }
diff --git a/src/main/java/no/nibio/vips/observationdata/ObservationDataSchema.java b/src/main/java/no/nibio/vips/observationdata/ObservationDataSchema.java
index 72434325..aa1da2bf 100755
--- a/src/main/java/no/nibio/vips/observationdata/ObservationDataSchema.java
+++ b/src/main/java/no/nibio/vips/observationdata/ObservationDataSchema.java
@@ -20,6 +20,7 @@ package no.nibio.vips.observationdata;
 
 import java.io.Serializable;
 import javax.persistence.Column;
+import javax.persistence.Convert;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
 import javax.persistence.NamedQueries;
@@ -28,8 +29,7 @@ import javax.persistence.Table;
 import javax.xml.bind.annotation.XmlRootElement;
 import no.nibio.vips.logic.util.StringJsonUserType;
 import org.hibernate.annotations.Type;
-import org.hibernate.annotations.TypeDef;
-import org.hibernate.annotations.TypeDefs;
+
 
 /**
  * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
@@ -38,7 +38,6 @@ import org.hibernate.annotations.TypeDefs;
 @Entity
 @Table(name = "observation_data_schema")
 @XmlRootElement
-@TypeDefs( {@TypeDef( name= "StringJsonObject", typeClass = StringJsonUserType.class)})
 @NamedQueries({
     @NamedQuery(name = "ObservationDataSchema.findAll", query = "SELECT o FROM ObservationDataSchema o"),
     @NamedQuery(name = "ObservationDataSchema.findByPK", query = "SELECT o FROM ObservationDataSchema o WHERE o.observationDataSchemaPK.organizationId = :organizationId AND o.observationDataSchemaPK.organismId = :organismId"),
@@ -49,11 +48,11 @@ public class ObservationDataSchema implements Serializable {
     private static final long serialVersionUID = 1L;
     @EmbeddedId
     protected ObservationDataSchemaPK observationDataSchemaPK;
-    @Type(type = "StringJsonObject")
+    @Convert(converter = StringJsonUserType.class)
     @Column(name = "data_schema")
     private String dataSchema;
-    @Type(type = "StringJsonObject")
-    @Column(name = "data_model")
+    @Convert(converter = StringJsonUserType.class)
+    @Column(name = "data_model", columnDefinition="json")
     private String dataModel;
 
     public ObservationDataSchema() {
diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml
index bfaf5ef4..5e68097c 100755
--- a/src/main/resources/META-INF/persistence.xml
+++ b/src/main/resources/META-INF/persistence.xml
@@ -25,8 +25,8 @@
     <jta-data-source>java:/jboss/datasources/vipslogic</jta-data-source>
     <class>no.nibio.vips.logic.messaging.MessageNotificationSubscription</class>
     <exclude-unlisted-classes>false</exclude-unlisted-classes>
-    <properties>
-      <property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisDialect"/>
-    </properties>
+    <!--properties>
+      <property name="hibernate.dialect" value="org.hibernate.spatial.dialect.postgis.PostgisPG10Dialect"/>
+    </properties-->
   </persistence-unit>
 </persistence>
-- 
GitLab