I'm implementing simple Blog application using JEE technologies-EJB's, JPA persistence, MySQL DB, Apache TomEE server. I am not sure how to annotate some of the types inside entities to be correctly mapped to appropriate mysql types.
For example, i have an entity named "Post" that has field "content", and here is how i have annotated it:
@Column(name = "post_content", columnDefinition = "TEXT", nullable = false)
private String content;
This field represents content of the blog post, and by its nature its length is not limited. (Blog post can be very long). I know that by default in JPA, String is being mapped to mysql varchar(255) type. This is the warning i am getting;
WARN [http-bio-8080-exec-10] openjpa.jdbc.Schema - Existing column "post_content" on table "post" is incompatible with the same column in the given schema definition. Existing column:
Full Name: post.post_content
Type: longvarchar
Size: 65535
Default: null
Not Null: true
Given column:
Full Name: post.post_content
Type: varchar
Size: 255
Default: null
Not Null: true
What is the proper way of annotating this kind of fields?
@Column(name = "post_content", length=65535)
private String content;
The warning is complaining that the default for the column attribute is 255, yet the database column has a length of 655535. If you specify the proper length the warning will go away.