0

I'm developing a Spring application where everything is configured with maven (in pom.xml). My application uses a PostgreSQL database, but unit tests use an in-memory HSQLDB database.

I just run into an issue with TEXT columns because they are not supported natively by HSQLDB. In my entity class I have :

private @Column(columnDefinition = "text") String propertyName;

This works fine with Postgres, but HSQLDB is generating the following error : type not found or user lacks privilege: TEXT. The table is not created, and of course as a result most of my tests fail.

I found that I need to activate PostgreSQL compatibility in order for this to work by setting sql.syntax_pgs to true.

My question is : where do I put this setting ? I would like to put it in pom.xml because everything is configured there, but I don't know where.

For exemple I have :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>-Dspring.profiles.active=test</argLine>
    </configuration>
</plugin>

Can I somehow add an <argLine> with this setting ?

deadbeef
  • 5,409
  • 2
  • 17
  • 47

2 Answers2

2

When you add hsqldb dependency it uses default connection properties. You can override these properties in property file or through other configuration as per your requirement. You can set "sql.syntax_pgs=true" to HSQLDB connection url. For example in case of spring boot this will be like below.

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
              <argLine>-Dspring.datasource.url=jdbc:hsqldb:mem:PUBLIC;sql.syntax_pgs=true</argLine>
        </configuration>
</plugin>
abaghel
  • 14,783
  • 2
  • 50
  • 66
0

you can set it in the Datasource configuration as given here

<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
   <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
   <property name="url" value="jdbc:hsqldb:mem:PUBLIC;sql.syntax_pgs=true" />
   <property name="username" value="sa" />
   <property name="password" value="" />
</bean>
Community
  • 1
  • 1
Deendayal Garg
  • 5,030
  • 2
  • 19
  • 33
  • Where do I put this ? Also I only want this to take effect when using the `test` profile. – deadbeef Sep 23 '16 at 13:26
  • you need to put this when you are configuring the HSQLDB for the tests. This property will be set for all the test using hsqldb. – Deendayal Garg Sep 23 '16 at 13:29
  • I'm not configuring HSQLDB anywhere, I just added it in `pom.xml` as a dependency, it's then used automatically by maven when running tests. – deadbeef Sep 23 '16 at 13:45