Internal representation of custom user types in Hibernate's 2nd level cache


Hibernate stores entities in a dehydrated form in its 2nd level cache. This works fine for me until custom user types enter the scene, particulary <a href="http://jadira.sourceforge.net/usertype-userguide.html" rel="nofollow">Jadira's UserType</a> library, which I use to map Joda time types.

Persistence works fine out of the box, but <a href="https://stackoverflow.com/questions/25869959/ehcache-hibernate-2nd-level-cache-maxbyteslocalheap-slow/26010141#26010141" rel="nofollow">I've discovered</a> that Hibernate will put a "raw" (serialized) reference to a LocalDate instance into its 2nd level cache, which causes some problems, because each LocalDate instance keeps tons of references to internal datastructures, which should not turn up in the cache.

Is there a way to hook into Hibernate's (de-)hydration strategy to get fine grain control over which data will eventually be stored in it's 2nd level cache?


Jadira's UserType library uses org.hibernate.usertype.UserType to implement its custom types. UserType instances are simply serialized when put into the 2nd level cache, which is a less then ideal choice for Joda time instances.

The Problem could be solved by using org.hibernate.usertype.CompositeUserType instead when implementing custom types, which gives you full control how entities should be (de-)hydrated when put into (or taken out of) the cache.

I filed a feature request with Jadira, but for now I'll just move forward by implementing my own custom types.


  • NHibernate: Default value for a property over a null column
  • php session expires randomly after a few minutes
  • How to check array of dates are consecutive from todays date? [duplicate]
  • Why LocalDate.plusDays not working here?
  • Java Arabic (Hirji) Calendar
  • Java 8 LocalDate in Grails 3.2 JSON view
  • Gradle compile dependencies not included in Jar
  • Server control behaving oddly
  • How to update data in Redis and MySQL at the same time?
  • How to fix: The return type of an async method must be void, Task or Task [AppName]
  • How to have NHibernate persist a String.Empty property value as NULL
  • How do I get NHibernate to save an entity if I assign it an ID, but generate one otherwise?
  • Applying custom annotation advice to spring data jpa repository
  • Android: Time calculations, how to add a specified amount of minutes
  • After Installing PMD in Luna in Prespective it is Not Showing?
  • How to mock current date?
  • Use neo4j server instead of embedded mode
  • Hibernate Joda DateTime Sorting
  • Is there any way to call saveCurrentTurnWithMatchData without sending a push notification?
  • Avoid registering duplicate broadcast receivers in Android
  • Ajax calls do not work in IE unless you fiddle with security settings
  • Keep this build forever option - Jenkins
  • debug library loaded with ctypes using gdb
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Highlight one bar in a series in highcharts?
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • script to move all files from one location to another location
  • Does CUDA 5 support STL or THRUST inside the device code?
  • How to show dropdown in excel using jrxml (jasper api)?
  • Why winpcap requires both .lib and .dll to run?
  • Calling of Constructors in a Java
  • PHP: When would you need the self:: keyword?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Running Map reduces the dimensions of the matrices
  • reshape alternating columns in less time and using less memory
  • Android Heatmap on canvas or ImageView