这是我收到的异常消息:
[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到项目感到有些困惑(不确定)。我没有更改代码,这是肯定的,但是我不知道该如何解决。感谢任何帮助。
最佳答案
该错误告诉您行大小太大-MySQL的最大行大小为65,535字节(请参见http://dev.mysql.com/doc/refman/5.0/en/column-count-limit.html)。
您应该更改comment_title
和comment_text
列的长度属性,以使总行大小小于65,535字节。您当前使用的值看起来就像您使用了一些默认值,而没有真正考虑什么是适当的限制。您真的要允许评论标题这么长吗?!
JPA创建的用于定义表的SQL将您的列设置为VARCHAR(65535),这可能使您认为这应该没问题,因为两个列的长度都是可变的,但事实并非如此。总行大小的计算假设表中的所有列均已充分使用-即VARCHAR(65535)列中存储了65,535个字节。我链接到的页面对此进行了解释,并提供了一个示例,该示例大约位于具有两个VARCHAR列的表的中途,而该列超出了限制。