有没有注解@Lob 有什么区别?

What difference does it make to put an annotation @Lob or not?

我的数据库中有一个请求 table。 这是它的结构

通常我都是用手创建实体,但这次我决定从数据库生成它。这是我得到的

@Entity
@Table(name = "request")
public class Request
{
    @Id
    @Column(name = "id", nullable = false)
    private Integer id;

    @Lob
    @Column(name = "body")
    private String body;

    @Column(name = "description", length = 10000)
    private String description;

    @Lob
    @Column(name = "headers")
    private String headers;

    @Column(name = "http_method", nullable = false, length = 20)
    private String httpMethod;

    @Column(name = "name", nullable = false, length = 100)
    private String name;

    @Lob
    @Column(name = "path_variables")
    private String pathVariables;

    @Column(name = "port")
    private Integer port;

    @Lob
    @Column(name = "query_params")
    private String queryParams;

    @Lob
    @Column(name = "url", nullable = false)
    private String url;

我注意到出现了一个奇怪的注解@Lob。 我以前从没见过她。我决定 Google 是什么意思以及为什么要放它。 找了很多答案都说需要这个注解让Hibernate明白这里可能有一个大对象

但在我看来,这个注释没有任何作用。毕竟,不管值不值,一切都是一样的?

What is it for?

从外观上看,您的实体生成工具只是用 @Lob 标记了所有未指定长度的列 - 很可能只是为了确保您放入其中的任何数据都会适合。
(比如说,在 Oracle 中最大 BLOB/CLOB 大小是 (4 GB - 1) * DB_BLOCK_SIZE initialization parameter (8 TB to 128 TB)

至于 @Lob 本身,javadoc 是这样说的:

Specifies that a persistent property or field should be persisted as a large object to a database-supported large object type. Portable applications should use the Lob annotation when mapping to a database Lob type. The Lob annotation may be used in conjunction with the Basic annotation or the ElementCollection annotation when the element collection value is of basic type. A Lob may be either a binary or character type.

The Lob type is inferred from the type of the persistent field or property, and except for string and character-based types defaults to Blob.

二进制 lob (BLOB) 的常见用例是在数据库中存储一些二进制文件内容,例如图像,对于字符 lob (CLOB) - 大型文本文档。