-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: hbm.xml not found
PostPosted: Sun Jan 04, 2009 9:20 am 
Newbie

Joined: Sun Oct 05, 2008 10:44 am
Posts: 7
i building a web application i have to insert values entered in to a JSP page to database using hibernate,i am a beginner at hibernate
i am getting this exception

org.hibernate.MappingNotFoundException: resource: LuceneApplication\WEB-INF\classes\InsertBean.hbm.xml not found


when i try to run my application
my files and directory structure is given below

LuceneApplication
|
|----->WEB-INF
| |
| |
| |-->classes
| | |-------- HibernateInsert.java
| | |-------- InsertBean.java
| | |-------- MyServlet.java
| | |-------- InsertBean.hbm.xml
| | |-------- hibernate.cfg.xml
| |
| |---------web.xml
| |---------lib
| |
|
|--------First.jsp

hibernate.cfg.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.url">
jdbc:postgresql://localhost/newgenlib
</property>
<property name="hibernate.connection.driver_class">
org.postgresql.Driver
</property>
<property name="hibernate.connection.username">
postgres
</property>
<property name="hibernate.connection.password">
girish
</property>
<property name="hibernate.connection.pool_size">
0
</property>
<!--<property name="hibernate.jdbc.batch_size">0</property>-->
<property name="hibernate.dialect">
org.hibernate.dialect.PostgreSQLDialect
</property>
<property name="hibernate.show_sql">
true
</property>
<!-- "Import" the mapping resources here -->
<mapping resource="LuceneApplication\WEB-INF\classes\InsertBean.hbm.xml"/>
</session-factory>
</hibernate-configuration>

InsertBean.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="InsertBean" table="InsertBean">
<!-- <id column="id" unsaved-value="-1" type="integer">
<generator class="sequence">
<param name="sequence">sequence_name</param>
</generator>
</id>-->
<property first="first" column="first" type="string"/>
<property first="middle" column="middle" type="string"/>
<property first="last" column="last" type="string"/>
</class>
</hibernate-mapping>


MyServlet.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
System.out.println("INSIDE SERVLET");
HibernateInsert hi=new HibernateInsert();
hi.insert();

}

}


InsertBean.java

public class InsertBean
{
String first;
String middle;
String last;
public InsertBean()
{
}
public InsertBean(String first,String middle,String last)
{
this.first=first;
this.middle=middle;
this.last=last;
}

public String getFirst()
{
return this.first;
}
public void setFirst()
{
this.first=first;
}
public String getMiddle()
{
return this.middle;
}
public void setMiddle()
{
this.middle=middle;
}
public String getLast()
{
return this.last;
}
public void setLast()
{
this.last= last;
}

}


HibernateInsert.java

import java.util.Date;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateInsert
{
public void insert(){
SessionFactory factory =
new Configuration().configure().buildSessionFactory();
Session session = factory.openSession();
session.beginTransaction();
InsertBean m1 = new InsertBean("new","gen","lib");
session.save(m1);
session.getTransaction().commit();
session.close();

}

}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2009 12:33 pm 
Beginner
Beginner

Joined: Sat Oct 18, 2008 10:25 am
Posts: 30
Hi,

try the following:

write only your package path into the hibernate.cfg.xml.

That's what I mean:


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

You don't need to write the whole path, only the package structure, but with a / instead of a point.

For example, your package structure is com.myApp.beans.InsertBean, then you have to write <mapping resource="com/myApp/beans/InsertBean.hbm.xml"/>


You can also try to replace the \ with a /.

<mapping resource="LuceneApplication/WEB-INF/classes/InsertBean.hbm.xml"/>


I hope, it helps.

Christopher


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2009 12:43 pm 
Newbie

Joined: Sun Oct 05, 2008 10:44 am
Posts: 7
Thank you for the reply i have tried it out but it didnt work


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2009 1:40 pm 
Beginner
Beginner

Joined: Sat Oct 18, 2008 10:25 am
Posts: 30
Nothing did change? You get the same exception?


Here is my own hibernate.cfg.xml, which works perfectly. Maybe you see some differences which I do not see.

Code:

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

<hibernate-configuration>
   <session-factory>
      <!-- MySQL -->

      <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost/esg</property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.connection.password">asdf</property>

      <property name="current_session_context_class">thread</property>
      <property name="hibernate.show_sql">true</property>
      <property name="hibernate.formate_sql">true</property>


      <!-- Mappings --> 
      <mapping resource="de/waldhausweg7/model/Lodger.hbm.xml" />
      <mapping resource="de/waldhausweg7/model/City.hbm.xml" />
      <mapping resource="de/waldhausweg7/model/Category.hbm.xml" />
      <mapping resource="de/waldhausweg7/model/Room.hbm.xml" />
      <mapping resource="de/waldhausweg7/model/Country.hbm.xml" />
      <mapping resource="de/waldhausweg7/model/Confession.hbm.xml" />
      <mapping resource="de/waldhausweg7/model/Study.hbm.xml" />
      <mapping resource="de/waldhausweg7/model/Rent.hbm.xml" />

   </session-factory>
</hibernate-configuration>



But I think about your problem again. Maybe I find the mistake.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2009 1:47 pm 
Beginner
Beginner

Joined: Sat Oct 18, 2008 10:25 am
Posts: 30
I have another idea.

You write

Quote:
<property first="middle" column="middle" type="string"/>


Correct is name instead of first.

Code:
<property name="middle" column="middle" type="string"/>


Here is a hmb.xml file from me.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false" auto-import="false">
   <class name="de.waldhausweg7.model.Room" table="Room">
      <id name="roomId" type="int">
         <generator class="assigned" />
      </id>
      <property name="basicRent" column="basicRent" />
      <property name="additionalCosts" column="additionalCosts" />
      <property name="livingSpace" column="livingSpace" />
      <property name="comment" column="comment" />
      
      <!-- 1:n-Beziehung zu Miete -->
      <set name="rents" cascade="none" lazy="true">
         <key column="roomId" />
         <one-to-many class="de.waldhausweg7.model.Rent" />
      </set>      
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 2:42 pm 
Newbie

Joined: Sun Oct 05, 2008 10:44 am
Posts: 7
thank you colbertz for your solution i checked my mapping and the path it worked but i am getting this problem also can u help me with this also



[url]http://forum.hibernate.org/viewtopic.php?p=2402647#2402647

thank you once again[/url]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.