保持 TEXT 数据类型时休眠错误 [英] Hibernate Error while persisting TEXT datatype
问题描述
使用 hibernate 和 mysql 5.5,我试图在数据库表的 TEXT 类型列中保留字符串值.
Using hibernate and mysql 5.5, I am trying to persist String value in TEXT type column of database table.
厌倦了在提到的列中设置字符串值并尝试保留数据.但是我遇到了以下异常.我已经使用 Netbeans 8.0 生成了实体类.
例外:-
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)
创建 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
}
在提出问题之前,我浏览了以下几乎没有帮助的链接.
Before raising question I went through following links which were of very little help.
- 我还尝试通过删除
@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"
- 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"
推荐答案
去掉@Lob和@Size注解,使用@Type(type="text")代替
remove the @Lob and @Size annotations, and use @Type(type="text") instead
工作.感谢@Maurice 和@Funtik
WORKED. Thanks @Maurice and @Funtik
这篇关于保持 TEXT 数据类型时休眠错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!