Java:Hibernate 和嵌入式 Derby;在其他位置/目录上创建 derby
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6429624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java: Hibernate and Embedded Derby; create derby on a other location/directory
提问by Benni
I haven't found anything to this on Google, but I think that's something that must be possible.
我在谷歌上没有找到任何关于这个的东西,但我认为这一定是可能的。
I got a serious Problem with my Hibernate Project:
我的 Hibernate 项目遇到了一个严重的问题:
I got two Modules, one Main-Module and one Tool-Module. They should use the same DB (an embedded Derby, because both Modules wouldn't be started at the same time).
我有两个模块,一个主模块和一个工具模块。它们应该使用相同的 DB(嵌入式 Derby,因为两个模块不会同时启动)。
So if i start a Module it creates the DB in Java Project-Directory, but i wan't the DB created a level "over" the Project Directory. The hibernate.cfg.xml, mapping Files and the DAOs are located in the Main-Module.
因此,如果我启动一个模块,它会在 Java 项目目录中创建数据库,但我不想让数据库在“项目目录”之上创建一个级别。hibernate.cfg.xml、映射文件和 DAO 位于主模块中。
So i want it to look so:
所以我希望它看起来像这样:
`rootDirecotry
|
+----myEmbeddedDerby
|
+----MainModule
|
+----ToolModule
But actually it looks so:
但实际上看起来是这样的:
`rootDirecotry
|
+----MainModule
| |
| +----myEmbeddedDerby
|
|
+----ToolModule
| |
| +----myEmbeddedDerby
This is the relevant part of my hibernate config-File:
这是我的休眠配置文件的相关部分:
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property>
<property name="hibernate.connection.password">password/property>
<property name="hibernate.connection.url">jdbc:derby:myEmbeddedDB;create=true</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
I would appreciate your help.
我会很感激你的帮助。
回答by user1380568
Set the property "derby.system.home" before Connection.
在连接之前设置属性“derby.system.home”。
private void setDerbyDBSystemDir() {
// Decide on the Derby db system directory: <userhome>/.anotherDir/for/DerbyDB
String systemDir = "./anotherDir/for/DerbyDB";
// Set the db system directory.
System.setProperty("derby.system.home", systemDir);
System.err.println("setDBSystemDir: derby.system.home="+systemDir);
}
回答by TOSHASHU123
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
org.apache.derby.jdbc.ClientDriver
</property>
<property name="hibernate.connection.url">
jdbc:derby://localhost:<port-No>/<dbName>;create=true
</property>
<property name="hibernate.connection.username">admin</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="/src/com/hbm/***.hbm.xml"/>
</session-factory>
</hibernate-configuration>
This will try, might be you'll get solution
这将尝试,也许你会得到解决方案
Using the above code, will help your solution.
使用上面的代码,将有助于您的解决方案。
回答by Puce
Try:
尝试:
<property name="hibernate.connection.url">jdbc:derby:../myEmbeddedDB;create=true</property>
Not sure, if this works, though.
不过,不确定这是否有效。