Correct JPA Annotation for PostgreSQL's text type without Hibernate Annotations

前端 未结 4 2066
抹茶落季
抹茶落季 2020-12-15 16:28

I\'m developing an application using:

  • Java 1.7
  • JPA (included in javaee-api 7.0)
  • Hibernate 4.3.8.Final
  • PostgreSQL-JDBC 9.4-1200-jdbc4
4条回答
  •  情书的邮戳
    2020-12-15 17:22

    Since the text type is not a part of the SQL standard there is no official JPA way I guess.

    However, the text type is quite similar to varchar, but without the length limit. You can hint the JPA implementation with the length property of @Column:

    @Column(length=10485760)
    private String description;
    

    Update: 10 MiB seems to be the maximum length for varchar in postgresql. The text is almost unlimited, according the documentation:

    In any case, the longest possible character string that can be stored is about 1 GB.

提交回复
热议问题