blaze-persistence icon indicating copy to clipboard operation
blaze-persistence copied to clipboard

Question. Can i use fields mapped as @Convert in multiset mode?

Open roma2341 opened this issue 1 year ago • 1 comments

I need to use this Hibernate entity field in my entity view:

  @Column(columnDefinition = "LONGTEXT", name = "party")
  @Convert(converter = CliedisParty_TypeConverter.class)
  Party_Type vendorParty;

But it says that multiset mode doesn't support it. Can I define a simple interface for vendorParty to map this field? This class had a lot of fields and I don't know how to create a custom blaze type for it without pain.

In this case, Blaze Persistence should do it as it has a converter and LONGTEXT type.

Update: I could easily write the custom type as it receives JSON as input, I thought that converter always receives tuples e.g ["1","2022-05-02","test"].

My converter:

public class BlazeVendorPartyType extends com.blazebit.persistence.view.spi.type.AbstractMutableBasicUserType<Party_Type> {

    CliedisParty_TypeConverter converter = new CliedisParty_TypeConverter();

        @Override
        public Party_Type deepClone(Party_Type object) {
            // Clone the object if it is mutable. For immutable types,
            // you can extend com.blazebit.persistence.view.spi.type.ImmutableBasicUserType and don't need this method
            if ( object == null) {
                return null;
            }
            var type = new Party_Type();
            return type;
        }

        @Override
        public String toStringExpression(String expression) {
            // A JPQL expression that produces a string format which is then parsed
            return expression;
        }

        @Override
        public Party_Type fromString(CharSequence sequence) {
            // The CharSequence has the format as defined through toStringExpression
            // Now it must be de-serialized to a Quantity
            return converter.convertToEntityAttribute(sequence.toString());
        }
    }

Or I may need to convert this columnDefinition to JSON and Blaze Persistence will know how to map it ?. I see some Blaze Jackson integrations, but what they do is unclear. do they only change internal mapping logic or allow the use of JSON column definition fields in entity views ?.

roma2341 avatar May 31 '24 12:05 roma2341

Looks like you figured how to do this already. Write a custom type like you did an leverage the converter in it to construct the object from the string. The Jackson integration only helps with deserializing entity-views from a JSON payload. Also see the documentation about this.

beikov avatar Jun 05 '24 18:06 beikov