gpt4 book ai didi

sql - Hibernate 4.1.2.FINAL 禁用上下文 LOB 创建,因为 createClob() 方法抛出错误,Blob 字段

转载 作者:行者123 更新时间:2023-11-29 11:43:49 25 4
gpt4 key购买 nike

我想用 hibernate/postgresql 9.1.1 创建一个 BLOB 字段

为什么我会在日志中看到这条消息:

INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-5)
HHH000424: Disabling contextual LOB creation as createClob() method threw error :
java.lang.reflect.InvocationTargetException

我知道这不是错误。

hibernate 4.1 文档:

"@Lob indicates that the property should be persisted in a Blob or a Clob depending
on the property type: java.sql.Clob, Character[], char[] and java.lang.String will be
persisted in a Clob. java.sql.Blob, Byte[], byte[] and Serializable type will be persisted in a Blob."

我这样声明我的字段:

@Lob
@Type(type = "org.hibernate.type.MaterializedClobType")
@Basic(fetch=javax.persistence.FetchType.LAZY)
@Column(name = "`ACTA_CERTIFICACION`")
public byte[] getActacertificacion() {
return actacertificacion;
}
/**
* @param actacertificacion
* @uml.property name="actacertificacion"
*/
public void setActacertificacion(byte[] actacertificacion) {
this.actacertificacion = actacertificacion;
}

但在数据库中,它的创建就像一个文本字段:

"ACTA_INCREMENTOSUSTITUCION" text

我能做什么?,我想创建一个字节字段或类似的东西。

最佳答案

因为您在数据库中使用text,所以您应该在POJO 类中使用CLOB 类型。如果你想映射这个,只需在你的 POJO 中添加一个属性,如下所示,

@Column(name="ACTA_INCREMENTOSUSTITUCION")
@Clob
private Clob tect;

现在,根据您的要求,您可以将此 Clob 转换为 byte[],如前所述 here .

关于sql - Hibernate 4.1.2.FINAL 禁用上下文 LOB 创建,因为 createClob() 方法抛出错误,Blob 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10392560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com