-->
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.  [ 1 post ] 
Author Message
 Post subject: mapping exception
PostPosted: Tue Feb 10, 2009 8:51 am 
Newbie

Joined: Mon Feb 09, 2009 9:40 am
Posts: 15
package one.hibi;

import java.util.*;

public class User {
private int id;
private String username;
private String password;

public User()
{

}

public void setId(int i) {
id = i;
}

public int getId() {
return id;
}

public void setUsername(String n) {
username = n;
}

public String getUsername() {
return username;
}

public void setPassword(String l) {
password = l;
}

public String getPassword() {
return password;
}
}
package one.hibi;
import java.util.Date;


import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateSession {



public static void main(String[] args) {
System.out.println("i am here");
SessionFactory factory;
Configuration cfg=new Configuration().addClass(User.class);System.out.println("i am here");
factory=cfg.buildSessionFactory();System.out.println("i am here");
Session s = factory.openSession();
System.out.println("i am here");
User u=new User();
u.setUsername("pawan");
u.setPassword("pawan");

//first one=new first();
//one.setFirst("hai");
//one.setSecond("bye");
s.save(u);
s.flush();
System.out.println("i got it");
s.close();


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

<hibernate-mapping>
<class name="User"
table="user">
<id name="id"
type="int"
unsaved-value="0">
<column name="id"
sql-type="int"
not-null="true"/>
<generator class="native"/>
</id>

<property name="username"/>
<property name="password"/>

</class>
</hibernate-mapping>

<?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 >

<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:mysql://localhost:3307/hibi</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">pawan</property>
<property name="hibernate.connection.password">pawan</property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for DB2 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping resource="one/hibi/User.hbm.xml"/>

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


Exception in thread "main" org.hibernate.MappingException: Could not read mappings from resource: one/hibi/User.hbm.xml
at org.hibernate.cfg.Configuration.addClass(Configuration.java:506)
at one.hibi.HibernateSession.main(HibernateSession.java:18)
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:425)
at org.hibernate.cfg.Configuration.addClass(Configuration.java:503)
... 1 more
Caused by: org.xml.sax.SAXParseException: Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:422)
... 2 more


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

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.