Hibernate 4.1.2.FINAL在createClob()方法引发错误,Blob字段时禁用上下文LOB创建

编程入门 行业动态 更新时间:2024-10-24 05:21:35
本文介绍了Hibernate 4.1.2.FINAL在createClob()方法引发错误,Blob字段时禁用上下文LOB创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

本文发布于:2023-10-28 23:33:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538089.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   字段   错误   方法   Hibernate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!