This is exception message I am getting:

[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]

This is the (part of the) Comment class:

@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
}

I had this code working with above annotations, and I was getting generated tables in database. To be honest, may be, that I have messed something about importing jars to project (not sure). I didn't change the code, that's for sure, but I don't know how to fix this. Appreciate any help.

有帮助吗?

解决方案

The error is telling you that your row size is too big - MySQL has a maximum row size of 65,535 bytes (see http://dev.mysql.com/doc/refman/5.0/en/column-count-limit.html).

You should change your length attributes for the comment_title and comment_text columns so that the total row size comes to under 65,535 bytes. The values you are using at the moment look like you have used some default values without giving real thought to what an appropriate limit is. Do you really want to allow a comment title to be that long?!

The SQL that JPA created to define your table set your columns to VARCHAR(65535) which may have led you to believe that it should be fine as both columns are variable in length, but this is not the case. The total row size calculation assumes that all columns in your table are fully used - i.e. your VARCHAR(65535) column has 65,535 bytes stored in it. The page I linked to explains it and gives an example about half way down the page of a table with two VARCHAR columns that breaks the limit.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top