Hibernate postgresql/hsqldb TEXT column incompatibility problem

前端 未结 6 1706
醉酒成梦
醉酒成梦 2021-01-02 00:26

I have a problem using Hibernate and PostgreSQL for production and HSQLDB for testing.
I am using top-down approach letting Hibernate create database schema.
I a

相关标签:
6条回答
  • 2021-01-02 00:41

    Agree with @fredt. TEXT data type isn't standard SQL type, but extension that some engine supports.

    To enable PostgreSQL compatibility mode use sql.syntax_pgs=true in your connection parameters.

    0 讨论(0)
  • 2021-01-02 00:44

    Yes, you have a really big problem.

    DON'T USE ONE DATABASE ENGINE FOR TESTING, AND ANOTHER FOR PRODUCTION.

    You can hit upon problems you've never dreamed about.

    0 讨论(0)
  • 2021-01-02 00:48

    HSQLDB 2.1 and later has a PostgreSQL compatibility mode and supports the TEXT data type in this mode.

    0 讨论(0)
  • 2021-01-02 00:54

    To get H2 to work in compatability mode with PostgreSQL (useful for junit testing).

    # JDBC Driver
    jdbc.driverClassName=org.h2.Driver
    jdbc.url=jdbc:h2:mem:play;MODE=PostgreSQL;TRACE_LEVEL_SYSTEM_OUT=2;DB_CLOSE_DELAY=-1;IGNORECASE=TRUE;INIT=CREATE TABLE IF NOT EXISTS PG_CLASS (RELNAME text, RELKIND text);
    jdbc.username=sa
    jdbc.password=
    
    # general hibernate options
    hibernate.database=h2
    hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
    

    The create table PG_CLASS is required to allow Hibernate/JPA to correctly function. But other than that - pretty seamless.

    0 讨论(0)
  • 2021-01-02 00:58

    Yes, just try on blow to make HSQLDB run in PostgreSQL compatibility mode.

    jdbc.url=jdbc:h2:mem:mydb;sql.syntax_pgs=true
    
    0 讨论(0)
  • 2021-01-02 01:00

    The easiest way to deal with this specific issue is probably to not use the columnDefinition at all and instead to explicitly specify the column length with (for example)

    @Column(length=10000)
    

    It might also be that you could instead map it with @Lob(type = LobType.CLOB)

    but I'm not sure that is supported properly in HSQLDB. In Postgres it should give you your TEXT type.

    0 讨论(0)
提交回复
热议问题