持久化TEXT数据类型时出现Hibernate错误

时间:2014-08-02 11:12:06

标签: java mysql hibernate exception text

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

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



例外: -

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)

创建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
}

在提出问题之前,我经历了以下几乎没有帮助的链接。



  • 我还尝试通过删除@Lob来保留数据,将数据保存为“org.hibernate.engine.jdbc.BlobProxy@11e84b60”
  • 我尝试using @Column(columnDefinition = "TEXT")而不是@Lob,再次给出相同的结果。 “org.hibernate.engine.jdbc.BlobProxy@11e84b60”
  • 我尝试@Type(type="text")而不是@Lob,再次给出相同的结果。 “org.hibernate.engine.jdbc.BlobProxy@11e84b60”

1 个答案:

答案 0 :(得分:4)

  

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

的工作。谢谢@Maurice和@Funtik