JerryCai
JerryCai

Reputation: 1693

How to define a big string in Spring Roo annotation(or jpa annotation) entity, varchar(255) is not enough

In spring-roo entity, I define a content field to record the content of the article:

@NotNull
private String content;

But in mysql field, it mapped to varchar(255), it's too short to record a content of article so the following exception thrown:

ERROR org.hibernate.util.JDBCExceptionReporter - Data truncation: Data too long for column 'content' at row 1

My question is what's the big string field type in mysql? (In access db, it's "memo"), how to define this annotation in Spring Roo to make it record more data? Thanks

Upvotes: 4

Views: 4706

Answers (2)

jbbarquero
jbbarquero

Reputation: 2852

Try

@Column(columnDefinition="varchar(255)")

Upvotes: 1

Chris Snow
Chris Snow

Reputation: 24626

One option would be to add the Size annotation, e.g.

@NotNull
@Size(max = 500)
private java.lang.String content;

Another option would be to use a LOB field:

@NotNull
@Lob
private byte[] content;

If I need a String field larger than about 255 characters, I usually use a LOB field. However, note that it is generally not possible to search for data inside a LOB field.

Upvotes: 5

Related Questions