I have a type that is very much like an enum. In order to allow my entities to have a property of this type, I've created a UserType and registered it globally in the following manner:
Now let's say that I have an entity:Code:@MappedSuperclass @TypeDef(defaultForType=My.class, typeClass=MyType.class) public class MyType implements UserType { // code that marshals to/from a VARCHAR via a name() field on a My object }
This works perfectly with Hibernate. Objects are persisted and deserialized correctly. Now let's create a nice Spring Data Repository:Code:@Entity public class MyEntity { private My my; public My getMy() { return my; } protected void setMy(My my) { this.my = my; } // ... other fields }
This does not work. Instead of using the globally-specified MyType for serializing the My object, Spring uses its own logic. This obviously fails. Moreover, when I try to replace the My with a String and call findByMy with my.name(), Spring tries to be too smart for its own good and declares that the given parameter doesn't match the class of the property.Code:public interface MyRepository extends JpaRepository<MyEntity, Integer> { MyEntity findByMy(My my); }
The conflation of these two issues seems to make it impossible to effectively use UserTypes with Spring Data. Am I missing some XML or other configuration incantation that I must perform to make this work?


Reply With Quote