Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to implement a Hibernate UserType after deprecations?

I recently got the latest version of Hibernate and noticed that my UserTypes now have warnings about AbstractStandardBasicType's nullSafeGet(ResultSet,String) and nullSafeSet(PreparedStatement,T,int) methods being deprecated in favor of their corresponding methods that take a SessionImplementor argument. The problem is that when you implement a UserType, the SessionImplementor doesn't get passed to you the way that is does in BasicType, CompositeUserType, etc.

I checked the Hibernate manual to see if there was an updated example. Their UserType example uses get/set instead of nullSafeGet/nullSafeSet, but those methods were also deprecated in favor of versions that take a SessionImplementor. So, it seems like even Hibernate's official UserType example is using deprecated methods, which leads me to wonder two things:

  1. Is there a good way to get the SessionImplementor from within the UserType?
  2. If it isn't practical to get the SessionImplementor from within UserType, and I don't want to write my own nullSafeGet/nullSafeSet, should I abandon UserType in favor of one of its alternatives? What are the practical differences between UserType and, for example, BasicType?
like image 630
spaaarky21 Avatar asked May 21 '11 18:05

spaaarky21


1 Answers

Thanks to Ryan Ransford for his comment on my original question. Although it's not really a solution to the problem, the link he provided from the Hibernate developers mailing list explains why no solution is available.

A non-deprecated alternative cannot be provided in 3.6.x, because doing so would break implementations of UserType.

Considering that these are just deprecation warnings, it doesn't make sense to invest too much time in a workaround that will be obsolete when the next non-maintenance release is available. Unfortunately, the next big release is 4.0, not 3.7, so migrating might be a little more involved.

like image 134
spaaarky21 Avatar answered Oct 12 '22 16:10

spaaarky21