持久化TEXT数据类型时出现Hibernate错误 [英] Hibernate Error while persisting TEXT datatype

查看:293
本文介绍了持久化TEXT数据类型时出现Hibernate错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用hibernate和mysql 5.5,我试图在数据库表的TEXT类型列中保留String值。

Using hibernate and mysql 5.5, I am trying to persist String value in TEXT type column of database table.

厌倦了在所提到的列中设置String值,并尝试保留数据。但是我得到以下异常。我已经使用Netbeans 8.0生成了Entity类。





例如:
例外: -

Tired to set String value in the mentioned column and tried to persist the data.But i am getting following exception. I have generated Entity class using Netbeans 8.0.



Exception:-

FATAL:   JSF1073: javax.faces.FacesException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=, Message=/addNewCategory.xhtml @30,151 actionListener="#{categoryBean.addCategoryAction}": java.lang.AbstractMethodError: com.mysql.jdbc.ServerPreparedStatement.setCharacterStream(ILjava/io/Reader;J)V
FATAL:   /addNewCategory.xhtml @30,151 actionListener="#{categoryBean.addCategoryAction}": java.lang.AbstractMethodError: com.mysql.jdbc.ServerPreparedStatement.setCharacterStream(ILjava/io/Reader;J)V
javax.faces.FacesException: /addNewCategory.xhtml @30,151 actionListener="#{categoryBean.addCategoryAction}": java.lang.AbstractMethodError: com.mysql.jdbc.ServerPreparedStatement.setCharacterStream(ILjava/io/Reader;J)V
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89)

CREATE SQL: -

 CREATE TABLE `oc_category_description` (
      `category_id` int(11) NOT NULL,
      `language_id` int(11) NOT NULL,
      `name` varchar(255) NOT NULL,
      `description` text NOT NULL,
      `meta_description` varchar(255) NOT NULL,
      `meta_keyword` varchar(255) NOT NULL,
      PRIMARY KEY (`category_id`,`language_id`),
      KEY `name` (`name`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

/*!40101 SET character_set_client = @saved_cs_client */;

EntityClass

@Entity
@Table(name = "oc_category_description")
@XmlRootElement
public class OcCategoryDescription implements Serializable {
    private static final long serialVersionUID = 1L;

    @Basic(optional = false)
    @NotNull
    @Lob
    @Size(min = 1, max = 65535)
    @Column(name = "description")
    private String description;

     public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}
    //Constructors, setters, getters, equals and hashcode
}

在提出问题之前,我经历了以下链接,帮助很小。

Before raising question I went through following links which were of very little help.

  • JPA: how do I persist a String into a database field, type MYSQL Text
  • JPA and PostqreSQL: long string persistence
  • Issue persisting long strings with Hibernate



  • 我还尝试通过删除 @Lob 来保存数据,将数据保存为org.hibernate.engine.jdbc。 BlobProxy @ 11e84b60

  • 我试过使用@Column(columnDefinition = TEXT)而不是 @Lob ,再次给出相同的结果。 org.hibernate.engine.jdbc.BlobProxy@11e84b60

  • 我试过 @Type(type =text)而不是 @Lob ,再次给出相同的结果。 org.hibernate.engine.jdbc.BlobProxy@11e84b60

  • I also tried to persist data by removing @Lob, it saving data as "org.hibernate.engine.jdbc.BlobProxy@11e84b60"
  • I tried using @Column(columnDefinition = "TEXT") instead of @Lob, again its giving same result. "org.hibernate.engine.jdbc.BlobProxy@11e84b60"
  • I tried @Type(type="text")instead of @Lob, again its giving same result. "org.hibernate.engine.jdbc.BlobProxy@11e84b60"

推荐答案


删除@Lob和@Size注释,并使用@Type(type =text)
替代

remove the @Lob and @Size annotations, and use @Type(type="text") instead

的工作。感谢@Maurice和@Funtik

WORKED. Thanks @Maurice and @Funtik

这篇关于持久化TEXT数据类型时出现Hibernate错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆