【问题标题】:PersistenceException: Row size too largePersistenceException:行大小太大
【发布时间】: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",并且我正在数据库中获取映射表,这些字符串字段属于TEXT mysql 类型。但是,如果没有明确定义columnDefinition="TEXT",为什么它不能工作?它不应该创建varchar(65535) 类型字段吗?

标签: java jpa openjpa


【解决方案1】:

错误是告诉您您的行大小太大 - MySQL 的最大行大小为 65,535 字节(请参阅http://dev.mysql.com/doc/refman/5.0/en/column-count-limit.html)。

您应该更改 comment_titlecomment_text 列的长度属性,以使总行大小低于 65,535 字节。您目前使用的值看起来像是使用了一些默认值,而没有真正考虑过适当的限制是什么。你真的要让评论标题这么长吗?!

JPA 为定义您的表而创建的 SQL 将您的列设置为 VARCHAR(65535),这可能使您认为这应该没问题,因为两列的长度都是可变的,但事实并非如此。总行大小计算假定表中的所有列都已完全使用 - 即您的 VARCHAR(65535) 列中存储了 65,535 个字节。我链接到的页面对其进行了解释,并给出了一个示例,该示例位于一个表的页面的一半左右,其中两个 VARCHAR 列打破了限制。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-29
    • 2019-05-17
    • 2017-08-06
    • 1970-01-01
    • 2013-06-27
    • 2021-04-11
    • 2016-02-23
    • 1970-01-01
    相关资源
    最近更新 更多