• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate package problem

 
kumaran dhakshna
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ranchers,,

i am new to hibernate i am tring to insert a new row in a table. while executing the program i am getting the following error.

pls help me.!!

Hibernate.cfg.xml file is


<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://192.168.1.149/products</property>
<property name="connection.username">root</property>
<property name="connection.password">rootproperty>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>

<!-- Drop and then re-create schema on SessionFactory build, for testing. -->
<!-- <property name="hbm2ddl.auto">create</property> -->


<!-- mapping files -->
<mapping resource="Model/honey.hbm.xml"/>
</session-factory>
</hibernate-configuration>



Error is


%%%% Error Creating SessionFactory %%%%
net.sf.hibernate.MappingException: Error reading resource: Model/honey.hbm.xml
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:990)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:946)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:874)
at Framework.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:76)
at View.Client.createHoney(Client.java:47)
at View.Client.main(Client.java:18)
Caused by: net.sf.hibernate.MappingException: org.dom4j.DocumentException: Connection refused: connect Nested exception: Connection refused: connect
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:293)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:333)
... 6 more
Caused by: org.dom4j.DocumentException: Connection refused: connect Nested exception: Connection refused: connect
at org.dom4j.io.SAXReader.read(SAXReader.java:358)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:283)
... 7 more
java.lang.NullPointerException
at Framework.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:84)
at View.Client.createHoney(Client.java:47)
at View.Client.main(Client.java:18)
Exception in thread "main"
 
Peter Laurinec
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mapping of the resources is done like this
<mapping resource="DomainModelClassName.hbm.xml"/>, so no path included.

Example: <mapping resource="Person.hbm.xml/>"

Please note that you hbm.xml classes should be located together with your domainmodel classes.

Hopefuly this helps.
 
kumaran dhakshna
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for you reply..

my application structure is


hibernateSample
|
|
|-- hibernate.cfg.xml
|
|-- Model
|
|-- Honey.java-- model class (DB Table)
|-- Honey.class
|-- Honey.hbm.xml
|
|-- View
|
|-- Client.java
|-- Client.class standalone program mapping the honey class and insert row to the table.


so i mapped like
<mapping resource="Model/Honey.hbm.xml"/>

what is the problem with this mapping ??

Is that possible to map a hbm.xml which is with in a package pls help....



The Error is
net.sf.hibernate.MappingException: Error reading resource: Model/Honey.hbm.xml
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:990)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:946)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:874)
 
Sunil Dixit
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As per ur application structure is concerned u have put ur Honey.hbm.xml under hibernateSample directory.
So replace <mapping resource="Model/Honey.hbm.xml"/> with <mapping resource="Honey.hbm.xml"/>
it will work
And far as ur question is concerned about mapping hbm.xml file to package level then yes u can.
I give u example.
suppose i have package struture like
com.sunil.hibernate.pojo
and under this package i have one POJO class say Student.java as well as student.hbm.xml file.
Under com.sunil.hibernate.util package i have one util class "HibernateUtil.java" which is reponsible for building the SessionFactory.
And at project level i have kept my hibernate.cfg.xml file.
So to map student.hbm.xml in hibernate.cfg.xml i will write this line of code
<mapping resource="com/sunil/hibernate/dao/student.hbm.xml"/>

and to build the session factory i will write following code in HibernateUtil.java
new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();

Hope that this make more clear picture

Sunil Dixit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic