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

使用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
}

在提出问题之前,我通过以下链接获得了很少的帮助.

> 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”

最佳答案

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

的工作.谢谢@Maurice和@Funtik

转载注明原文:java – 持久化TEXT数据类型时出现Hibernate错误 - 代码日志