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



我想用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[],如此处所述。

相关内容

最新更新