postgresql Hibernate 4.1.2.FINAL 禁用上下文 LOB 创建,因为 createClob() 方法抛出错误,Blob 字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10392560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hibernate 4.1.2.FINAL Disabling contextual LOB creation as createClob() method threw error , Blob field
提问by Vodo-Siosk Baas
I want to create a BLOB field with hibernate/postgresql 9.1.1
我想用 hibernate/postgresql 9.1.1 创建一个 BLOB 字段
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
I know this is not an error.
我知道这不是错误。
Hibernate 4.1 documentation:
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."
I declare my field like this:
我这样声明我的领域:
@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.
我能做什么?,我想创建一个字节字段或类似的东西。
回答by ManuPK
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,
由于您text
在数据库中使用,您应该CLOB
在 POJO 类中使用类型。如果你想映射这个,只需在你的 POJO 中添加一个属性,如下所示,
@Column(name="ACTA_INCREMENTOSUSTITUCION")
@Clob
private Clob tect;
Now, as per your requirement you can convert this Clobto a byte[]as told here.
现在,根据您的要求,您可以按照此处的说明将此Clob转换为byte[]。