Tests are already written that used Sql Server and worked but I am going back and trying with H2 just to speed things up. The entity is this:
已经编写了使用Sql Server并且工作的测试,但是我回过头来尝试使用H2来加快速度。实体是这样的:
@Entity
@Table(name="Rules"
,schema="dbo"
,catalog="ABM"
)
public class Rules {
....
}
which was generated for me with reverse engineering against Sql Server and I intend to have test using H2 with that entity. However I get:
这是针对我为Sql Server进行逆向工程而生成的,我打算使用H2与该实体进行测试。但是我得到:
Caused by: org.h2.jdbc.JdbcSQLException: Schema "ABM" not found; SQL statement:
with show sql set to true I see:
将show sql设置为true我看到:
... from abm.dbo.rules ....
H2 must not know what 'abm' is. Looking into creating a schema I updating the url to this:
H2一定不知道'abm'是什么。在研究创建模式时,我将URL更新为:
spring.datasource.url=jdbc:h2:mem:ABM;INIT=CREATE SCHEMA ABM;AUTO_SERVER=TRUE;USE SCHEMA ABM
Still having the same problem. Can I use an entity created for Sql Server with catalog set to something in H2?
还有同样的问题。我可以使用为Sql Server创建的实体,并将目录设置为H2中的某些内容吗?
Thanks ahead of time.
提前谢谢。
1 个解决方案
#1
0
How I got around this was that the entity has catalog and schema and for H2 there really isn't the concept of catalogs. Catalogs are basically just database and you can create schemas so I did this:
我如何解决这个问题是实体有目录和模式,对于H2,实际上没有目录的概念。目录基本上只是数据库,您可以创建模式,所以我这样做:
@Primary
@Bean(name = "h2soruce")
public DataSource dataSource() {
EmbeddedDatabase build = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).setName("ABM").addScript("init.sql").build();
return build;
}
and under resources init.sql had this
并且在资源下init.sql有这个
CREATE SCHEMA IF NOT EXISTS dbo;
found that on github: demo-spring-data-jpa-hibernate-h2
在github上发现:demo-spring-data-jpa-hibernate-h2
#1
0
How I got around this was that the entity has catalog and schema and for H2 there really isn't the concept of catalogs. Catalogs are basically just database and you can create schemas so I did this:
我如何解决这个问题是实体有目录和模式,对于H2,实际上没有目录的概念。目录基本上只是数据库,您可以创建模式,所以我这样做:
@Primary
@Bean(name = "h2soruce")
public DataSource dataSource() {
EmbeddedDatabase build = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).setName("ABM").addScript("init.sql").build();
return build;
}
and under resources init.sql had this
并且在资源下init.sql有这个
CREATE SCHEMA IF NOT EXISTS dbo;
found that on github: demo-spring-data-jpa-hibernate-h2
在github上发现:demo-spring-data-jpa-hibernate-h2