Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

java - Hibernate Error while persisting TEXT datatype

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

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.



  • 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"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

WORKED. Thanks @Maurice and @Funtik


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...