从 UserType 上下文获取 LobHelper
Get LobHelper from a UserType context
我正在将旧的 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)
,但我不知道如何从会话中获取 LobHelper,因为我没有 Session
,只有 SessionImplementor
:
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor implementor) { ...
我发现了 ContextualLobCreator(LobCreationContext)
class,SessionImplementor
实现了 LobCreationContext
,所以我基本上转换了
Blob blob = Hibernate.createBlob((byte[]) value);
至
Blob blob = new ContextualLobCreator(implementor).createBlob((byte[]) value);
我正在将旧的 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)
,但我不知道如何从会话中获取 LobHelper,因为我没有 Session
,只有 SessionImplementor
:
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor implementor) { ...
我发现了 ContextualLobCreator(LobCreationContext)
class,SessionImplementor
实现了 LobCreationContext
,所以我基本上转换了
Blob blob = Hibernate.createBlob((byte[]) value);
至
Blob blob = new ContextualLobCreator(implementor).createBlob((byte[]) value);