File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes class not found exception while running my first hebernate example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "class not found exception while running my first hebernate example" Watch "class not found exception while running my first hebernate example" New topic
Author

class not found exception while running my first hebernate example

kiran kumar reddy
Ranch Hand

Joined: Jun 28, 2012
Posts: 94

i am a newbie to hibernate i was trying to run my first hibernate program but it says "class not found exception"
i was running in eclipse IDE and i have attached all jars and i ran Manager.java....i am attaching a screen shot of my eclipse error and details of my program......
here is Person.hbm.xml file contents...i use Oracle XE with port n0:5656......

<?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">
<hibernate-mapping package="kiran.kumar">
<class name="Person" table="PERSON">
<id name="id" column="PERSON_ID">
<generator class="native"/>
</id>
<property name="age"/>
<property name="firstName" column="first_name"/>
<property name="lastName" column="last_name"/>

</class>
</hibernate-mapping>
_________________________________________________________________________

here is my Person.java file
package kiran.kumar;

public class Person {
private Integer id;
private String firstName;
private String lastName;
private Integer age;
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id=id;
}
public String getfirstName()
{
return firstName;
}
public void setfirstName(String firstName)
{
this.firstName=firstName;
}
public String getlastName()
{
return lastName;
}
public void setlastName(String lastName)
{
this.lastName=lastName;
}
public Integer getAge()
{
return age;
}
public void setAge(Integer age)
{
this.age=age;
}
}
_____________________________________________________________________________________________________

......
please help me to correct my error


[Thumbnail for hibernate_cgf_xml.JPG]

[Thumbnail for eclipse_structure.JPG]

Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 484

You are missing Apache Commons logging JAR file.


PM Me If You Want to get Urgent Help on Java Programming
kiran kumar reddy
Ranch Hand

Joined: Jun 28, 2012
Posts: 94

thanks for your reply dude but where can i download it dude??
kiran kumar reddy
Ranch Hand

Joined: Jun 28, 2012
Posts: 94

thanks dude,now the error changed and it says following error
>>>>>>>
Exception in thread "main" org.hibernate.MappingNotFoundException: resource: kiran/kumar/Manager.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 org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at kiran.kumar.Manager.main(Manager.java:18)
<<<<<<<
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 484

The Manager.hbm.xml should be placed under src/kiran/kumar directory.
kiran kumar reddy
Ranch Hand

Joined: Jun 28, 2012
Posts: 94

@nam ha minh.... there is no such file Manager.hbm.xml......there are only the below
1. Manager.java
2. person.java
3. Person.hbm.xml
4. hibernate.cfg.xml...
i am using Oracle XE with port number 5656.....i am attaching screen shot of hibernate config file check it weather it has errors or not....
after some attempts of my trying to correct this program finnaly i got this error......
>>>>>>>>>>>>
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.InvalidMappingException: Could not parse mapping document from resource kiran/kumar/Person.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
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 org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
at kiran.kumar.Manager.main(Manager.java:18)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:502)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 7 more
Caused by: org.xml.sax.SAXParseException: Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)
... 8 more
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


[Thumbnail for hibernate_cfg.png]

kiran kumar reddy
Ranch Hand

Joined: Jun 28, 2012
Posts: 94

@hi all
at last my errors reduced to minimum extent and i created table in the data base but values are not inserted in the table.....
now console looks like following
>>>>>>>>>>
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into PERSON (age, first_name, last_name, PERSON_ID) values (?, ?, ?, ?)
<<<<<<<<<<
 
jQuery in Action, 2nd edition
 
subject: class not found exception while running my first hebernate example
 
Similar Threads
class not found exception while running my first hebernate example
cannot insert record in MS SQLServer 2000
Mapping in Hibernate for nested Bean Structure
Hibernate mapping
/hibernate.cfg.xml not found while Running simple java program