Discussion:
Hibernate Reverse Engineering with Netbeans
dainol
2010-09-28 07:43:37 UTC
Permalink
Hello,
Im working on a small application with hibernate and spring. My project works good, but the mapping files are incomplete so I decided to use Reverse Engineering to create them automatically.

I have some problems when I try to use Hibernate Tools for Reverse Engineering from Netbeans (create mapping files from cfg.xml and database)

For the Hibernate Reverse Engineering Wizard a hibernate.cfg.xml is required.
I only had a xml file, where the settings for my database connection and for hibernate are stored, because thats possible with using Spring. So
now I splitted them in two: the xml file for my database is now looking like this:

applicationContext.xml

Code:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<tx:annotation-driven transaction-manager="txManager"/>

<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
<property name="dataSource" ref="securityDataSource" />
</bean>


<bean id="securityDataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.user}"/>
<property name="password" value="${db.password}"/>
</bean>

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="WEB-INF/config/backend/db.properties"/>
</bean>


</beans>




and this is my hibernate.cfg.xml


Code:

<?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">

<hibernate-configuration>

<session-factory>

<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>

<mapping resource="users.hbm.xml"/>

</session-factory>

</hibernate-configuration>




Unfortunately by trying to create the reverse engineering file I get this errormessage:

the database drivers are not added to the project classpath. go to project properties and add database library


Thats not possible??! I can run the project and the database connection IS working!! So what is missing that I can not create that reverse engineering file??? I tried every library I could imagine.

Until yesterday I used SpringFramework 3.0.2
I even changed to 3.0.4 to see if it would work
I use hibernate3.jar and the mysql jdbc connector 5.1.6

Here I got two pictures with my libraries in build path. please help!! thanks in advance!

Loading Image.../
Loading Image.../
dainol
2010-10-01 08:54:27 UTC
Permalink
has nobody an idea?!?
dainol
2010-10-05 16:43:16 UTC
Permalink
Im a little bit disappointed. This is the NetBeans Forum. Where, when not here, can I get an answer???
Rick
2010-10-05 18:19:57 UTC
Permalink
Can you please include the thread here? We have no idea what you are
talking about.
Post by dainol
Im a little bit disappointed. This is the NetBeans Forum. Where, when not here, can I get an answer???
JeffRubinoff
2010-10-05 20:02:33 UTC
Permalink
To be fair, you can always view the thread by going to the forum page, which in this case is http://forums.netbeans.org/viewtopic.php?t=31899.
Rick
2010-10-05 23:48:05 UTC
Permalink
It would be nice if that were included in the post to make it easy to
look up.

Thanks,

Rick
Post by JeffRubinoff
To be fair, you can always view the thread by going to the forum page, which in this case is http://forums.netbeans.org/viewtopic.php?t=31899.
Jeffrey Rubinoff
2010-10-06 10:04:10 UTC
Permalink
Hmm. OT, but that sounds like a nice enhancement to ask our web guy
about...
Post by Rick
It would be nice if that were included in the post to make it easy to
look up.
Thanks,
Rick
Post by JeffRubinoff
To be fair, you can always view the thread by going to the forum
page, which in this case is
http://forums.netbeans.org/viewtopic.php?t=31899.
Ken Ganfield
2010-10-06 12:30:03 UTC
Permalink
Hi
I do not really have experience using Hibernate and Spring, but it could
be that the Reverse Engineering wizard is expecting the connection
details for the database in cfg.xml and when it does not find the
details it becomes confused and does not know how to connect to the db
and fails.

You could try adding the db details to cfg.xml and then trying to run
the wizard to see if it will generate the reveng file. If that works and
you have the reveng file, you could then delete the details from cfg.xml
if it is a problem for spring.

ken
Post by dainol
Hello,
Im working on a small application with hibernate and spring. My project works good, but the mapping files are incomplete so I decided to use Reverse Engineering to create them automatically.
I have some problems when I try to use Hibernate Tools for Reverse Engineering from Netbeans (create mapping files from cfg.xml and database)
For the Hibernate Reverse Engineering Wizard a hibernate.cfg.xml is required.
I only had a xml file, where the settings for my database connection and for hibernate are stored, because thats possible with using Spring. So
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
<property name="dataSource" ref="securityDataSource" />
</bean>
<bean id="securityDataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.user}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="WEB-INF/config/backend/db.properties"/>
</bean>
</beans>
and this is my hibernate.cfg.xml
<?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">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<mapping resource="users.hbm.xml"/>
</session-factory>
</hibernate-configuration>
the database drivers are not added to the project classpath. go to project properties and add database library
Thats not possible??! I can run the project and the database connection IS working!! So what is missing that I can not create that reverse engineering file??? I tried every library I could imagine.
Until yesterday I used SpringFramework 3.0.2
I even changed to 3.0.4 to see if it would work
I use hibernate3.jar and the mysql jdbc connector 5.1.6
Here I got two pictures with my libraries in build path. please help!! thanks in advance!
http://img42.imageshack.us/f/bibs1.png/
http://img33.imageshack.us/f/bibs2.png/
dainol
2010-10-06 15:34:41 UTC
Permalink
after looking over it, it looks a little bit... strange
do you think that the reverse engineering wizard always generates files which are right???? can I trust it?!

for example, I have a table users (username, password, enabled)

now, in the other tables were I have a foreign key referencing users(username), there is now not a column username in the hbms and pojos but a object from users... I hope that is right...
dainol
2010-10-06 14:01:28 UTC
Permalink
first to the persons who were asking what Im talking about - I clicked "answer" to my thread and my answer appears right under my thread, Im a little bit confused why you cant see it. For me everything looks normal... (?)

to ken.ganfield:
thanks for your answer! I was thinking to that this might be the problem. Unfortunately Spring needs the database and the other things to be configured in an extra file, otherwise there will be problems with the transaction management. But I can try to generate the files by changing the cfg.xml and then reverting it. Thats of course not the best way, but I will try it. I'll report if its working! Thank you!
dainol
2010-10-06 15:18:18 UTC
Permalink
ok, this seems to work. better than nothing. thanks for the hint which did not come in my mind ;-)
Jeffrey Rubinoff
2010-10-06 23:21:42 UTC
Permalink
Daniol,
Some people view j2ee as a forum. Some subscribe to it as an email
alias. Some people who do one are not aware that the other means exists.
If you only read this as emails, you only see the contents of the last post.
OK, 1:20 am here and I cannot write coherently in either email or forum
formats...

Jeff
Post by dainol
first to the persons who were asking what Im talking about - I clicked "answer" to my thread and my answer appears right under my thread, Im a little bit confused why you cant see it. For me everything looks normal... (?)
thanks for your answer! I was thinking to that this might be the problem. Unfortunately Spring needs the database and the other things to be configured in an extra file, otherwise there will be problems with the transaction management. But I can try to generate the files by changing the cfg.xml and then reverting it. Thats of course not the best way, but I will try it. I'll report if its working! Thank you!
Rick
2010-10-07 19:36:22 UTC
Permalink
OK, nbusers is not set up that way (as far as I know). The software
should be set to mail the thread if it is sending out mail.
Post by Jeffrey Rubinoff
Daniol,
Some people view j2ee as a forum. Some subscribe to it as an email
alias. Some people who do one are not aware that the other means
exists. If you only read this as emails, you only see the contents of
the last post.
OK, 1:20 am here and I cannot write coherently in either email or
forum formats...
Jeff
Post by dainol
first to the persons who were asking what Im talking about - I
clicked "answer" to my thread and my answer appears right under my
thread, Im a little bit confused why you cant see it. For me
everything looks normal... (?)
thanks for your answer! I was thinking to that this might be the
problem. Unfortunately Spring needs the database and the other things
to be configured in an extra file, otherwise there will be problems
with the transaction management. But I can try to generate the files
by changing the cfg.xml and then reverting it. Thats of course not
the best way, but I will try it. I'll report if its working! Thank you!
dainol
2010-10-07 09:57:01 UTC
Permalink
Post by Jeffrey Rubinoff
Daniol,
Some people view j2ee as a forum. Some subscribe to it as an email
alias. Some people who do one are not aware that the other means exists.
If you only read this as emails, you only see the contents of the last post.
OK, 1:20 am here and I cannot write coherently in either email or forum
formats...
Jeff
I understand. I also saw now the "posted via mailing list" under the names.
Sorry. I have another problem, but I will make a new thread for it, so its not offtopic. thanks again for the help.[/quote]
dainol
2010-10-07 09:58:27 UTC
Permalink
Post by Jeffrey Rubinoff
Daniol,
Some people view j2ee as a forum. Some subscribe to it as an email
alias. Some people who do one are not aware that the other means exists.
If you only read this as emails, you only see the contents of the last post.
OK, 1:20 am here and I cannot write coherently in either email or forum
formats...
Jeff
I understand. I also saw now the "posted via mailing list" under the names.
Sorry. thanks for the help. if the problem cannot be solved otherwise, I will live with this solution. Its a little bit circuitous, but better than nothing. ;-) This thread can be "closed" now.
Loading...