Hibernate 4.1.2.FINAL在createClob()方法引发错误,Blob字段时禁用上下文LOB创建 [英] Hibernate 4.1.2.FINAL Disabling contextual LOB creation as createClob() method threw error , Blob field
问题描述
我想用hibernate/postgresql 9.1.1创建一个BLOB字段
I want to create a BLOB field with hibernate/postgresql 9.1.1
为什么我会在日志中看到此消息:
Why do I see this message in the logs:
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文档:
Hibernate 4.1 documentation:
"@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;
}
但是在数据库中,它的创建就像一个文本字段:
But in the database its create like a text field:
"ACTA_INCREMENTOSUSTITUCION" text
我该怎么办?,我想创建一个字节字段或类似的内容.
What can I do?, I want to create a byte field or something similar.
推荐答案
由于您在数据库中使用text
,因此应该在POJO类中使用CLOB
类型.如果要对此进行映射,只需在POJO中添加一个属性,如下所示,
Since the you are using text
in database, you should be using CLOB
type in the POJO class. If you want to map this, just add a property in your POJO as below,
@Column(name="ACTA_INCREMENTOSUSTITUCION")
@Clob
private Clob tect;
Now, as per your requirement you can convert this Clob to a byte[] as told here.
这篇关于Hibernate 4.1.2.FINAL在createClob()方法引发错误,Blob字段时禁用上下文LOB创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!