Internal representation of custom user types in Hibernate second-level cache

Hibernation stores objects in a dehydrated form in its second level cache. This works great for me until the custom types enter the scene, especially the Jadira UserType library which I use to display Joda time types.

Persistence works great, but I found that Hibernate will put the "raw" (serialized) instance reference LocalDate

in its 2nd level, which causes some problems as each instance LocalDate

stores many references to internal data structures that shouldn't appear in the cache.

Is there a way to hook into a hibernation (de-) hydration strategy to get the fine grain management by which the data will ultimately be stored in the L2 cache?


source to share

1 answer

The UserType library uses Jadira org.hibernate.usertype.UserType

to implement its custom types. UserType

the instances are simply serialized when inserted into the second-level cache, which is a less ideal choice for Joda time instances.

The problem can be solved by using org.hibernate.usertype.CompositeUserType

instead when implementing custom types, which gives you complete control over how objects should be (deactivated) when the cache is entered (or checked out).

I've submitted a feature request with Jadira, but for now I'm just moving forward by implementing my own custom types.



All Articles