3

我想用 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

我知道这不是错误。

休眠 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

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

4

1 回答 1

4

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

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

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

于 2012-05-01T12:12:10.013 回答