我想用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创建
发布评论