java - 使用maven配置HSQLDB

标签 java spring hibernate maven hsqldb

我正在开发一个 Spring 应用程序,其中所有内容都使用 maven 配置(在 pom.xml 中)。我的应用程序使用 PostgreSQL 数据库,但单元测试使用内存 HSQLDB 数据库。

我刚刚遇到了 TEXT 的问题列,因为 HSQLDB 本身不支持它们。在我的实体类中,我有:

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

这对于 Postgres 工作正常,但 HSQLDB 生成以下错误:type not found or user lacks privilege: TEXT 。该表未创建,当然,因此我的大多数测试都失败了。

我发现我需要 activate PostgreSQL compatibility为了使其工作通过设置 sql.syntax_pgstrue .

我的问题是:我应该把这个设置放在哪里?我想把它放在 pom.xml因为一切都在那里配置,但我不知道在哪里。

例如我有:

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

我可以添加一个 <argLine>用这个设置?

最佳答案

当您添加 hsqldb 依赖项时,它会使用默认连接属性。您可以根据您的要求在属性文件中或通过其他配置覆盖这些属性。您可以将“sql.syntax_pgs=true”设置为HSQLDB连接url。例如,在 Spring Boot 的情况下,如下所示。

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
              <argLine>-Dspring.datasource.url=jdbc:hsqldb:mem:PUBLIC;sql.syntax_pgs=true</argLine>
        </configuration>
</plugin>

关于java - 使用maven配置HSQLDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39661332/

相关文章:

java - 如何读取服务器文件并将其作为可下载文件在 XPage 的用户 Web 浏览器中输出

Java - 重写 hashCode 和 toString

java - 使用什么事务管理器? (JPA, Spring )

java - NonUniqueDiscoveredSqlAliasException 当两个表具有相同的列名时

java - 如何更新 ProgressDialog fragment

java - JAX-RS 授权获取更多数据

java - 插入具有单向多对多关系的新实体生成级联持久而不是级联合并

Java hibernate 异常 : could not deserialize

java - Spring addFormatters 未调用 WebMvcConfigurerAdapter

java - Spring 中的 PropertyEditor、Formatter 和 Converter 有什么区别?