简体   繁体   中英

Store JSON as a field in PostgreSQL with Spring Data JPA

I want to have a specific table with two columns, an ID and a field in which I'll store a JSON object. And I'm using Spring Data JPA.

I'm thinking of something in this line, but I'm not sure:

@Entity
@Table(name = "some_table")
public class SomeTable {

    @Id
    @Column(name = "id", unique = true)
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @GeneratedValue(generator = "uuid")
    private UUID id;

    // getters and setters for id here..

    // here to be the field for storing JSON objects and it's getters and setters
}

The answer depends on what version of PostgreSQL you are using. If you are using 9.1, check out https://bitbucket.org/adunstan/json_91 which gives you the same functionality you'd get in 9.2. If it is an older version you are going to have to go with text or backport that module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM