- This topic has 8 replies, 5 voices, and was last updated 18 years, 9 months ago by Brian Fernandes.
-
AuthorPosts
-
mb9923MemberHello,
I’ve been working through the hibernate quick start tutorial.
<a href=http://myeclipseide.com/enterpriseworkbench/help/index.jsp?topic=/com.genuitec.myeclipse.doc/html/quickstarts/hibernate/index.html>click here</a>After a lot of playing around I finally got it working, but here’s the catch:
My table was originally named “echo_message” in the MySQL database, but hibernate looks for a table called “testdb__echo_message”. When I created a new table with this name, the code I wrote worked. Here is my question: How do I make hibernate access my original table?
Thanks
MB
Riyad KallaMemberMB,
The table is specified in the HBM.XML file, take a look in there and see which file has testdb__echo_message specified and change it there… very odd.
mb9923MemberNone of the hibernate xml files even mention test_db_echo_message. Here is the contents of my hibernate.cfg.xml file:
<?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”><!– Generated by MyEclipse Hibernate Tools. –>
<hibernate-configuration><session-factory>
<property name=”connection.username”>root</property>
<property name=”connection.url”>jdbc:mysql://localhost/testdb</property>
<property name=”dialect”>org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name=”myeclipse.connection.profile”>testDB</property>
<property name=”connection.driver_class”>com.mysql.jdbc.Driver</property>
<property name=”max_fetch_depth”>1</property>
<mapping resource=”com/genuitec/hibernate/EchoMessage.hbm.xml” /></session-factory>
</hibernate-configuration>
And here is the contents of the EchoMessage.hbm.xml file:
<?xml version=”1.0″?>
<!DOCTYPE hibernate-mapping PUBLIC “-//Hibernate/Hibernate Mapping DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”>
<!–
Mapping file autogenerated by MyEclipse – Hibernate Tools
–>
<hibernate-mapping>
<class name=”com.genuitec.hibernate.EchoMessage” table=”echo_message” catalog=”testdb”>
<id name=”id” type=”integer”>
<column name=”id” />
<generator class=”native”></generator>
</id>
<property name=”msg” type=”string”>
<column name=”msg” />
</property>
</class>
</hibernate-mapping>As you can see, the xml files seem to be pointing toward the correct tables, but the code tries to access the wrong tables. Could this have something to do with the dialect prpoerty in the hibernate.cfg.xml file? Is there a setting that appends the database name to the beginning of the table name?
Thanks in advance for your help.
MB
toriwellsMemberHi mb9923,
I’ve just faced this problem today. I’ve solved it looking at the *.fbm.xml file (in your case EchoMessage.hbm.xml). As you can see, one of the attributes of the class tag is ‘catalog’. Just remove it and Hibernate will work on the table you want. The line would be as this:
<class name="com.genuitec.hibernate.EchoMessage" table="echo_message">
Good Luck!
mb9923MemberWow, that worked. Thanks!
axelbeckerMemberHallo,
i generate my hibernate mapping (myeclipse 4.1 and mysql 5) with dbexplorer.
At all times, i generate the Hibernate-Mapping new, i have to remove the catalog= in all XML’s.
Is it possible to generate the *.fbm.xml without the attribute “catalog=”? Perhabs i can modify the *.vm Templates?
thanks,
axel
Riyad KallaMemberIs it possible to generate the *.fbm.xml without the attribute “catalog=”? Perhabs i can modify the *.vm Templates?
Not at this time, but we want to open up the templating to folks to modify for this exact reason.
Also there was a whole slew of improvements comming in 4.1.1 to the DB exlporer as well as the hibernate work.
axelbeckerMemberThanks for your answer.
I tried to use customiezed templates (see http://myeclipseide.com/modules.php?op=modload&name=PNphpBB2&file=viewtopic&t=10964).
But it doesn’t work.
Now i use ANT to replace the tokens. It isn’t very nice. But it works.axel
Brian FernandesModeratorAxel,
The customized template mechanism has been tried and tested. It should certianly work for you.
Could you tell us the steps you followed, my thoughts are that you might have specified the wrong template folder or incorrectly modified the templates.The catalog issue however will be separately fixed for 4.1.1, turns out it was an issue with Hibernate and catalogs.
Best,
Brian. -
AuthorPosts