JPA中@javax.persistence.Lob注解的意义是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29511133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the significance of @javax.persistence.Lob annotation in JPA?
提问by Devender
When should I use @javax.persistence.Lob
annotation in JPA? What datatypes can be annotated by this annotation?
我@javax.persistence.Lob
什么时候应该在 JPA 中使用注解?这个注解可以注解哪些数据类型?
采纳答案by Zielu
@javax.persistence.Lob
signifies that the annotated field should be represented as BLOB (binary data) in the DataBase.
@javax.persistence.Lob
表示注释字段应在数据库中表示为 BLOB(二进制数据)。
You can annotate any Serializable
data type with this annotation.
In JPA, upon persisting (retrieval) the field content will be serialized (deserialized) using standard Java serialization.
您可以Serializable
使用此批注来批注任何数据类型。在 JPA 中,在持久化(检索)时,字段内容将使用标准 Java 序列化进行序列化(反序列化)。
Common use of @Lob
is to annotate a HashMap
field inside your Entity to store some of the object properties which are not mapped into DB columns. That way all the unmapped values can be stored in the DB in one column in their binarry representation. Of course the price that is paid is that, as they are stored in binary format, they are not searchable using the JPQL/SQL.
常见的用途@Lob
是注释HashMap
实体内的字段以存储一些未映射到数据库列的对象属性。这样,所有未映射的值都可以以二进制表示形式存储在数据库中的一列中。当然,付出的代价是,由于它们以二进制格式存储,因此无法使用 JPQL/SQL 进行搜索。
回答by levrun
According to: https://docs.oracle.com/javaee/7/api/javax/persistence/Lob.html
根据:https: //docs.oracle.com/javaee/7/api/javax/persistence/Lob.html
@LobSpecifies that a persistent property or field should be persisted as a large object to a database-supported large object type.
@Lob指定持久属性或字段应作为大对象持久化到数据库支持的大对象类型。
@javax.persistence.Lob signifies that the annotated field should be represented as BLOB (binary data) in the DataBase.
@javax.persistence.Lob 表示带注释的字段应在数据库中表示为 BLOB(二进制数据)。
I suppose in database it could be not only binary data but character-based. As we could have BLOB and CLOB. Here's examples in java code:
我想在数据库中它不仅可以是二进制数据,还可以是基于字符的。因为我们可以有 BLOB 和 CLOB。下面是java代码中的例子:
@Lob
@Column(name = "CHARS", columnDefinition = "CLOB")
private String chars;`
@Lob
@Basic(fetch = FetchType.LAZY)
@Column(name = "DATA", columnDefinition = "BLOB", nullable = false)
private byte[] data;