【问题标题】:Get LobHelper from a UserType context从 UserType 上下文中获取 LobHelper
【发布时间】:2015-04-10 14:13:54
【问题描述】:

我正在将旧的 Hibernate 2.x 代码迁移到 4.x。其中一个类是 byte[] 和 Blob 之间的 UserType,代码执行如下操作:

public void nullSafeSet(...) {
    ...
    Blob blob = Hibernate.createBlob(bytes);
    ...
}

在 Hibernate 4.x 中,Hibernate.createBlob 不再存在,所以我需要使用session.getLobHelper().createBlob(bytes),但我不知道如何从 Session 中获取 LobHelper,因为我没有 @987654324 @,只有一个SessionImplementor

public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor implementor) { ...

【问题讨论】:

    标签: hibernate hibernate-4.x usertype


    【解决方案1】:

    我发现了ContextualLobCreator(LobCreationContext)这个类,而SessionImplementor实现了LobCreationContext,所以我基本转换了

    Blob blob = Hibernate.createBlob((byte[]) value);
    

    Blob blob = new ContextualLobCreator(implementor).createBlob((byte[]) value);
    

    【讨论】:

      猜你喜欢
      • 2019-09-02
      • 2011-11-09
      • 2011-07-15
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-19
      • 1970-01-01
      相关资源
      最近更新 更多