开发者

Java EE JPA 2 Entity Mappings

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:

  1. 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...)?
  2. 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


  1. Add column attributes has only sense for varchar/char fields. Text/longtext couldn't be optimized by explicit length spec.
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜