【发布时间】:2013-12-23 11:34:33
【问题描述】:
这是我收到的异常消息:
[java] Exception in thread "main" javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
[java] javax.ejb.EJBTransactionRolledbackException: The transaction has been marked rollback only because the bean encountered a non-application exception :org.apache.openjpa.persistence.PersistenceException : Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs {stmnt 23775157 CREATE TABLE comment (comment_id INTEGER NOT NULL AUTO_INCREMENT, comment_content VARCHAR(65535) NOT NULL, comment_date DATETIME NOT NULL, comment_title VARCHAR(65535) NOT NULL, user_id INTEGER NOT NULL, post_id INTEGER NOT NULL, PRIMARY KEY (comment_id), UNIQUE U_COMMENT_COMMENT_ID (comment_id)) ENGINE = innodb} [code=1118, state=42000]
这是Comment 类的(部分):
@Entity
@Table(name = "comment")
public class Comment implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "comment_id", unique = true, nullable = false)
private Integer id;
@Column(name = "comment_title", length=65535, unique = false, nullable = false)
private String title;
@Column(name = "comment_date", unique = false, nullable = false)
private Date date;
@Column(name = "comment_content", length=65535, unique = false, nullable = false)
private String content;
@ManyToOne
@JoinColumn (name = "user_id", referencedColumnName="user_id", nullable = false)
private User user;
@ManyToOne
@JoinColumn (name = "post_id", referencedColumnName="post_id", nullable = false)
private Post post;
// ... getters and setters
}
我让这段代码与上述注释一起工作,并且我正在数据库中获取生成的表。老实说,可能是我在将 jar 导入项目方面搞砸了(不确定)。我没有更改代码,这是肯定的,但我不知道如何解决这个问题。感谢任何帮助。
【问题讨论】:
-
好吧,我已经为每个具有
length=65535的字符串字段添加了columnDefinition="TEXT",并且我正在数据库中获取映射表,这些字符串字段属于TEXTmysql 类型。但是,如果没有明确定义columnDefinition="TEXT",为什么它不能工作?它不应该创建varchar(65535)类型字段吗?