开发者

Java: Hibernate and Embedded Derby; create derby on a other location/directory

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:

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).

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.

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.h开发者_如何学JAVAibernate.dialect.DerbyDialect</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

I would appreciate your help.


Try:

<property name="hibernate.connection.url">jdbc:derby:../myEmbeddedDB;create=true</property>

Not sure, if this works, though.


Set the property "derby.system.home" before Connection.

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);
}


<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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜