一尘不染

保持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 */;

实体类

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

阅读 231

收藏
2020-06-20

共1个答案

一尘不染

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

工作。谢谢

2020-06-20