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

前端 未结 4 2065
抹茶落季
抹茶落季 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:09

    I would go with simple private String description;. The column type is only a problem if you are generating the database from your code, because it will be generated as varchar instead of text.

    It is great to code in database agnostic way, and without any JPA vendor specific things, but there are cases where this just isn't possible. If the reality is that you will have to support multiple database types with all their specifics, then you have to account for those specifics somewhere. One option is to use columnDefinition for defining column type. Another is to leave the code as it is, and just change the column type in the database. I prefer the second one.

提交回复
热议问题