I have a MySQL database with the follow开发者_高级运维ing:
`title` text,
`content` longtext,
and have them mapped to the following Entity attributes:
private String title;
private String content;
Here are my questions:
- When entering a value, does the JPA automatically detect the size of text and longtext, or do I have to annotate the attributes with @Column(length...)?
- I have seen people using the @Lob annotation on strings. In this case would it be suitable to use it (and on which attributes)?
Thanks
- Add column attributes has only sense for varchar/char fields. Text/longtext couldn't be optimized by explicit length spec.
- Use @Lob for both fields
text
datatype of MySQL is actually an LOB, or better say CLOB (character strings or LOB). So, yes it would be very much suitable to annotate it using @Lob
.
精彩评论