views:

160

answers:

1

I'm following http://netbeans.org/kb/docs/java/hibernate-java-se.html tute to setup hibernate with derby in netbeans IDE.

Netbeans fails to create hibernate.reveng.xml with error : "Cannot establish database connection with selected Hibernate Configuration file. Please verify the database connection details in hibernate.cfg.xml"

My hibernate.cfg.xml looks like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property>
    <property name="hibernate.connection.url">jdbc:derby:G:\projects\Java\DesktopApplication1\db;create=true</property>
    <property name="hibernate.connection.username">user</property>
    <property name="hibernate.connection.password">***</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
  </session-factory>
</hibernate-configuration>

and database is accessible on this path.

Any idea?

+1  A: 

Found this in netbeans log file: java.sql.SQLException: Another instance of Derby may have already booted the database G:\projects\Java\DesktopApplication1\db.

Just a guess but you have maybe an SQL client still connected. Or maybe the database didn't shutdown properly. Try to specify a shutdown=true in the connection string.

Actually, my suggestion would be to use Derby in server mode, NetBeans provides excellent support for it. See Working with the Java DB (Derby) Database.

Pascal Thivent
First of all, thanks for the answer. No, I tried to do this after restarting computer, still same error. Tried shutdown=true as well. I use derby only because it can be embedded, otherwise I would use MySQL. This app should be able to work in network, many apps on same db, then I would use server mode.
umpirsky
@umpirsky: I don't know. FWIW, I'm using Derby with Hibernate (in-memory, embedded, server mode) and I don't face the problem you're mentioning. Actually, I don't face any problem, Derby is a very nice database, robust and is well supported by Hibernate.
Pascal Thivent
Why it's not in the upper list on http://community.jboss.org/wiki/SupportedDatabases ?
umpirsky
@umpirsky: I don't know. Do whatever you want, I'm just letting readers know that Derby works well with Hibernate.
Pascal Thivent
OK, will give it a deeper test ;)
umpirsky
In server mode it works well, no locking and netbeans generates nice pojos. Except, for generated primary keys it puts <generator class="assigned" /> instead <generator class="identity" />, that took some time to figure out.And, netbeans does not generate foreign key references <many-to-one... in xml or java pojos. Any idea?
umpirsky