• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate configuration problem..

 
labi laba
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am a newbie to hibernate. I am having problems in configuration.Following few tutorials/books,I have my

hibernate.cfg.xml: in my classpath i.e., in /src folder outside any package.
xxx.hbm.xml: inside /src/mypackage where other .java files reside.

It wasn't able to find con file... so i explicitly set the path and passed it as an arg to configure method.
File file = new File("C:/HibernateExample/src/java/hibernate.cfg.xml");
SessionFactory sessionFactory = new Configuration().configure(file).buildSessionFactory();

Now that it has found conf file, its not able to locate the mapping file xxx.hbm.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://mysql.wolfram.com:3324/search_info_tst</property>
<property name="hibernate.connection.username">search_user_tst</property>
<property name="hibernate.connection.password">wrselohetst</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="xxx.hbm.xml"/>
</session-factory>
</hibernate-configuration>

even i tried out <mapping resource="C:/HibernateExample/src/java/mypackage/xxx.hbm.xml"/>.. but failed
any suggestions/ideas are most welcome.... thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so it is in the src/java directory.

Also you need relative path to the hbm files so not

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

but

<mapping resource="mypackage\xxx.hbm.xml"/>

There is still something wrong with your classpath though. Because if the hibernate.cfg.xml was truly in your classpath, you would not need the File() created and sent as a parameter.

How do you set your classpath?

Mark
 
labi laba
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, i was messing up with the classpath. Now its working fine. but thanks alot for your response.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by labi laba:
yeah, i was messing up with the classpath. Now its working fine. but thanks alot for your response.


Glad we could help.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic