Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PersistenceException:行大小太大_Java_Jpa_Openjpa - Fatal编程技术网

Java PersistenceException:行大小太大

Java PersistenceException:行大小太大,java,jpa,openjpa,Java,Jpa,Openjpa,这是我收到的异常消息: [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 b

这是我收到的异常消息:

[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]
这是
注释
类的(部分):

@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导入到project中弄糟了(不确定)。我没有更改代码,这是肯定的,但我不知道如何修复此问题。感谢您的帮助。

错误告诉您行大小太大-MySQL的最大行大小为65535字节(请参阅)

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


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

好的,我为每个长度为
length=65535
的字符串字段添加了
columnDefinition=“TEXT”
,并在数据库中获得了映射表,这些字符串字段是
TEXT
mysql类型。但是,为什么没有明确定义
columnDefinition=“TEXT”
,它就不能工作呢?它不应该创建
varchar(65535)
type字段吗?