Javatpoint Logo

My question is I unable to execute the Hibernate Programes in eclipse?

By: suryan*** On: Sat Mar 05 00:27:06 IST 2016     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
when i was setting and running the Hibernate app in Eclipse following errors are coming in Console, so please let me what i need do?

Console:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: employee.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:563)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1584)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1552)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1531)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1505)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at com.surya.model.StoreData.main(StoreData.java:12)
Up0Down

 
Image Created0Down

By: [email protected] On: Wed May 25 16:21:25 IST 2016 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No
 
Hibernate XML mapping file contains the mapping relationship between Java class and database table. This is always named as ?xxxxxx.hbm.xml? and declared in the Hibernate configuration file ?hibernate.cfg.xml?.

In your case, you are trying to map employee.hbm.xml to your code. But hibernate is not able to find the classpath of file. you need to check following things given below.--

1- Check the configuration is done properly in hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
......
<mapping resource="com/mkyong/common/Stock.hbm.xml"></mapping>
......
</session-factory>
</hibernate-configuration>

For any reasons you do not want to include the mapping file in hibernate.cfg.xml. Hibernate provides a method for developer to add mapping file programmatically.

Just modify the default Hibernate SessionFactory class by passing your ?hbm.xml? file path as an argument into the addResource() method:

Java
SessionFactory sessionFactory = new Configuration()
.addResource("com/mkyong/common/Stock.hbm.xml")
.buildSessionFactory();
Image Created0Down

By: [email protected] On: Mon Jun 06 11:10:59 IST 2016 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No