在 playframework 中使用 @Lob 作为字段
剧中!教程中,模型Post的content
字段注释为@Lob。我尝试了这个,当postgres
用作db时,发现表Post 有一个名为 content 的列,其值为
133414
而不是一个长字符串,即帖子内容。列类型显示为 'text'
,其中其他实体中的字符串字段是字符变化
假设,我想搜索内容中包含特定单词的帖子,我将如何制定查询?我是否必须删除@Lob注释并让postgres将内容存储为内容列中的varchar?
In the play! tutorial,the content
field of model Post is annotated as @Lob.I tried this, and when postgres
was used as db,found that the table Post
has a column named content which has a value 133414
instead of a long string, which was the post content.The column type is shown as 'text'
where as other String fields in Entity were character varying
Suppose,I want to search for posts that contain a certain word in their content,how would I formulate the query? Will I have to remove the @Lob annotation and let postgres store the content as varchar in the content column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@Lob 根据定义是一个大对象。它可以存储为二进制数据或字符数据。在 lobs/clob/blob 中搜索可能非常困难,并且在大多数情况下并未优化。我建议使用更传统的类型,例如 text、varchar。它们是可索引的,因此性能更高。 (在大多数情况下),您可能还必须定义列大小。
您可以使用列注释来精确它们:
A @Lob is by definition a Large Object. That can be stored as binary data or character data. Searching in lobs/clob/blob can be very difficult and is, in most cases, not optimized. I would suggest using more traditionnal types such as text, varchar. Those are indexable and thus are more performant. (in most cases), you might have to define column size also.
You can precise them using the column annotation :