jpa建表时设置字段为longtext类型

需求:描述字段存json串儿

    @Lob
    @Basic(fetch= FetchType.LAZY)

关于解释:

https://blog.csdn.net/sunrainamazing/article/details/80783402

   [@Lob]标签:

   指定持久属性或字段应作为大对象持久保存到数据库支持的大对象类型。

    映射到数据库Lob类型时,便携式应用程序应使用Lob注释。 
    当元素集合值是基本类型时,Lob注释可以与Basic注释或ElementCollection注释一起使用。 
    Lob可以是二进制或字符类型。

  Lob类型是根据持久性字段或属性的类型推断的,除了字符串和基于字符的类型以外,默认为Blob。
   1. String 类的默认值 为 longtext
   2. byte[]  Image  File 默认值 为 longblob
 

domo例子验证:

1.创建实体:

package com.nutvideo.nvideo.entity;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;


@Entity
@Getter
@Setter
@Table(name = "book_entity")
public class BookEntity {

    private static final long serialVersionUID = -8129812756230022406L;


    @Override
    public String toString() {
        return "BookEntity{" +
                "name='" + name + '\'' +
                ", description='" + description + '\'' +
                '}';
    }

    private String name; //1.标题string|视频标题|

    @Lob
    @Basic(fetch= FetchType.LAZY)
    private String description; //2.描述简介


}

运行启动项目:

猜你喜欢

转载自blog.csdn.net/jack_bob/article/details/105856321