本文介绍了弃用后实现Hibernate UserType的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近获得了最新版本的Hibernate,并注意到我的UserType现在有关于AbstractStandardBasicType的nullSafeGet(ResultSet,String)和nullSafeSet(PreparedStatement,T,int)方法的警告,它们是。问题是,当你实现一个UserType时,SessionImplementor不会像BasicType,CompositeUserType等那样传递给你。

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.

我检查了Hibernate手动查看是否有更新的示例。他们的UserType示例使用get / set而不是nullSafeGet / nullSafeSet,但这些方法也被弃用,以支持采用SessionImplementor的版本。因此,看起来Hibernate的官方UserType示例使用了不推荐使用的方法,这导致我想知道两件事情:

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. 有没有好方法从UserType中获取SessionImplementor?

  2. 如果从UserType中获取SessionImplementor并且我不想编写自己的nullSafeGet / nullSafeSet,那么应该如何抛弃UserType而转向其中一种选择? UserType和BasicType之间的实际区别是什么?


推荐答案

感谢Ryan兰斯福德对我原来的问题发表了评论。虽然这不是真正解决问题的办法,但他提供的 Hibernate开发人员邮件列表解释了为什么没有解决方案可用。

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.

考虑到这些只是弃用警告,投入太多没有意义这种解决方法在下一个非维护版本可用时将会过时。不幸的是,下一个大版本是4.0,而不是3.7,所以迁移可能会涉及更多。

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.

这篇关于弃用后实现Hibernate UserType的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 23:46