columnDefinition = “TEXT” for all types of databases

前端 未结 4 1002
无人共我
无人共我 2021-02-20 03:53

Locally I use mysql, so when I use

 @Column(columnDefinition = \"TEXT\")

Unfortunately application have to run at different databases too, I\'

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 04:45

    Similiar Problem I was getting error while uploading an image into the mysql database, @Column(columnDefinition = “TEXT”).
    You can use in postgresql as well as mysql database's.

    Just I've changed to

    @Lob
    @Column(name=imageFiie)
    private String image;
    

    Note: When working with PostgresSQL we may, periodically, need to store a string with an arbitrary length.

    For this, PostgreSQL provides three character types:

    1. CHAR(n)
    2. VARCHAR(n)
    3. TEXT. Unfortunately, the TEXT type is not part of the types that are managed by the SQL standard. This means that if we want to use JPA annotations in our persistence entities, we may have a problem.

    This is because the JPA specification makes use of the SQL standard. Consequently, it doesn't define a simple way to handle this type of object using, for example, a @Text annotation.

    Luckily, we have a couple of possibilities for managing the TEXT data type for a PostgreSQL database:

    We can use the @Lob annotation Alternatively, we can also use the @Column annotation, combined with the columnDefinition attribute

提交回复
热议问题