Class AbstractSetType<T>

java.lang.Object
com.broadleafcommerce.common.jpa.usertype.AbstractSetType<T>
Type Parameters:
T - The type of the set elements
All Implemented Interfaces:
org.hibernate.usertype.EnhancedUserType<Set<T>>, org.hibernate.usertype.UserType<Set<T>>
Direct Known Subclasses:
InitializingStringSetType, StringSetType

public class AbstractSetType<T> extends Object implements org.hibernate.usertype.EnhancedUserType<Set<T>>
A Hibernate UserType for Sets that need conversion to/from Json. In the past, this has been handed with a JPA converter, but as of Hibernate 6, Sets are handled differently with conversion happening on the individual constituents, instead of the entire Set. This was causing issues with type discovery and conversion based on design expectations. Changing this case to a Hibernate UserType instead works around the issue, and returns the behavior for this type of field handling to what it was previously.
  • Constructor Details

    • AbstractSetType

      public AbstractSetType(Class<?> elementType, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
    • AbstractSetType

      public AbstractSetType(Class<?> elementType, com.fasterxml.jackson.databind.ObjectMapper objectMapper, boolean initIfNull)
  • Method Details

    • getSqlType

      public int getSqlType()
      Specified by:
      getSqlType in interface org.hibernate.usertype.UserType<T>
    • returnedClass

      public Class<Set<T>> returnedClass()
      Specified by:
      returnedClass in interface org.hibernate.usertype.UserType<T>
    • equals

      public boolean equals(Set<T> x, Set<T> y)
      Specified by:
      equals in interface org.hibernate.usertype.UserType<T>
    • hashCode

      public int hashCode(Set<T> x)
      Specified by:
      hashCode in interface org.hibernate.usertype.UserType<T>
    • nullSafeGet

      public Set<T> nullSafeGet(ResultSet rs, int position, org.hibernate.engine.spi.SharedSessionContractImplementor session, Object owner) throws SQLException
      Specified by:
      nullSafeGet in interface org.hibernate.usertype.UserType<T>
      Throws:
      SQLException
    • nullSafeSet

      public void nullSafeSet(PreparedStatement st, Set<T> value, int index, org.hibernate.engine.spi.SharedSessionContractImplementor session) throws SQLException
      Specified by:
      nullSafeSet in interface org.hibernate.usertype.UserType<T>
      Throws:
      SQLException
    • toSqlLiteral

      public String toSqlLiteral(Set<T> value)
      Specified by:
      toSqlLiteral in interface org.hibernate.usertype.EnhancedUserType<T>
    • toString

      public String toString(Set<T> value) throws org.hibernate.HibernateException
      Specified by:
      toString in interface org.hibernate.usertype.EnhancedUserType<T>
      Throws:
      org.hibernate.HibernateException
    • deepCopy

      public Set<T> deepCopy(Set<T> value)
      Specified by:
      deepCopy in interface org.hibernate.usertype.UserType<T>
    • disassemble

      public Serializable disassemble(Set<T> value)
      Specified by:
      disassemble in interface org.hibernate.usertype.UserType<T>
    • isMutable

      public boolean isMutable()
      Specified by:
      isMutable in interface org.hibernate.usertype.UserType<T>
    • fromStringValue

      public Set<T> fromStringValue(CharSequence sequence) throws org.hibernate.HibernateException
      Specified by:
      fromStringValue in interface org.hibernate.usertype.EnhancedUserType<T>
      Throws:
      org.hibernate.HibernateException
    • assemble

      public Set<T> assemble(Serializable cached, Object owner)
      Specified by:
      assemble in interface org.hibernate.usertype.UserType<T>
    • getJson

      protected String getJson(Set<T> value)