Best way to implement a Hibernate UserType after deprecations?

不想你离开。 提交于 2019-12-19 05:14:43

问题


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?

回答1:


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.



来源:https://stackoverflow.com/questions/6083768/best-way-to-implement-a-hibernate-usertype-after-deprecations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!