使用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
using @Column(columnDefinition = "TEXT")
@Type(type="text")
删除@Lob和@Size批注,并使用@Type(type =“ text”)代替
工作。谢谢