Spring嵌入式数据库是否支持不同的SQL方言? [英] Does Spring embedded database support different SQL dialects?

查看:185
本文介绍了Spring嵌入式数据库是否支持不同的SQL方言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

H2为各种其他数据库(如MS)提供了一系列兼容模式支持不同SQL方言的SQL Server,MySQL,Oracle等。但是,在设置 Spring中的嵌入式数据库我找不到任何相应的设置。这是否意味着如果我在生产中使用Oracle而在测试期间使用H2,那么我必须使用没有任何方言特定功能的普通SQL?我忽略了什么吗?

解决方案

根据 H2 doc ,Oracle兼容模式非常有限。



例如,你不能使用PL / SQL程序。 / p>

如果使用Spring的EmbeddedDatabase,则不能按原样设置兼容模式;你必须实现自己的 EmbeddedDatabaseConfigurer 并通过JDBC URL指定兼容模式(见下文)。



但是,为了在H2和Spring中使用兼容模式,你只需要在经典的JDBC URL中设置模式(因此它与Spring不相关)方式,使用DataSource:

  jdbc:h2:〜/ test; MODE = Oracle 

如果使用Hibernate,则必须指定Oracle方言而不是H2方言。


H2 has a range of compatibility modes for various other databases such as MS SQL Server, MySQL, Oracle, etc that support different SQL dialects. However, when setting up an embedded database in Spring I do not find any corresponding setting. Does this imply that I have to use "plain" SQL without any dialect specific features if I for example use Oracle in production and H2 during test? Have I overlooked something?

解决方案

According to the H2 doc, the Oracle compatibility mode is quite limited.

For instance, you can not use PL/SQL procedures.

If you use Spring's EmbeddedDatabase, you cannot set the compatibility mode as-is; you have to implement you own EmbeddedDatabaseConfigurer and specify the compatibility mode through the JDBC URL (see below).

But also, to use the compatibility mode with H2 and Spring, you just have to set the mode in your JDBC URL (so it is not Spring related) in a classic way, using a DataSource:

jdbc:h2:~/test;MODE=Oracle

And if you use Hibernate, you have to specify the Oracle dialect instead of the H2 one.

这篇关于Spring嵌入式数据库是否支持不同的SQL方言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆