简体   繁体   English

休眠,从文件加载架构

[英]Hibernate, load schema from file

In Hibernate, I can use hbm2dll tool to import data files after hibernate generates the schema from my model. 在Hibernate中,hibernate从模型中生成架构后,可以使用hbm2dll工具导入数据文件。 This is fine, but I want to load the file with my database schema and make hibernate use that instead of generating one. 很好,但是我想用数据库模式加载文件,并使休眠模式使用它而不是生成一个。

Let's say I have some database configured in my hibernate config 假设我在休眠配置中配置了一些数据库

<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:."/>

Now before I run my test I want to load the db with some schema defined in my schema.sql file. 现在,在运行测试之前,我想使用在schema.sql文件中定义的某些架构加载数据库。 And I don't want to use Spring , I know there is support for it there. 而且我不想使用Spring ,我知道那里有它的支持。

I know I could use hibernate.hbm2ddl to generate schema when SessionFactory is created but I'd rather want to load my manually defined schema. 我知道在创建SessionFactory时可以使用hibernate.hbm2ddl生成架构,但是我想加载手动定义的架构。 Something like <jdbc:embedded-database> from spring-jdbc. 类似于spring-jdbc中的<jdbc:embedded-database>

Is there any support for that in Hibernate? Hibernate是否对此提供任何支持?

link1 and link2 might help you out. link1link2可能会帮助您。

Also you can set hibernate.hbm2ddl to none , and add your import.sql file in the classpath which will be executed at the server startup. 您也可以将hibernate.hbm2ddl设置为none ,并将import.sql文件添加到将在服务器启动时执行的类路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM