The JavaDoc for EnhancedUserType says
A custom type that may function as an identifier or discriminator type
But when I create an EnhancedUserType for my own types and use them in an entity for the ID column like this
@Entity
public class EntityB {
@Id
@Type(StringWrapperUserType.class)
public StringWrapper id;
}
and I create a relation to this entity like this
@Entity
public class EntityA {
@Id
@Type(StringWrapperUserType.class)
private StringWrapper id;
@OneToMany(cascade = CascadeType.ALL)
private Set<EntityB> entityBSet;
}
then I get an exception when I try to access the Set. The exception
The problem is, that in the unwrap method a String array is created, but the code tries to assign a StringWrapper instance. See org.hibernate.type.descriptor.java.ArrayJavaType#unwrap
I created a reproducer, which is based on Quarkus 3.2.1.Final, which uses hibernate-core in version 6.2.6.Final. Beside of the application properties there is no Quarkus specific functionality/code inside. Reproducer: https://github.com/timonzi/hibernate-user-type-for-relation Simply execute a mvn clean install and the error will occur. |