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: error in cfg.xml and hbm.xml
PostPosted: Thu Jul 29, 2010 1:43 am 
Newbie

Joined: Thu Jul 29, 2010 1:34 am
Posts: 1
I am developing a hibernate application eclipse. Following is the code.
Book.java
package sampack;

public class Book {
private long lngBookId;
private String strBookName;

/**
* @return Returns the lngBookId.
*/
public long getLngBookId() {
return lngBookId;
}
/**
* @param lngBookId The lngBookId to set.
*/
public void setLngBookId(long lngBookId) {
this.lngBookId = lngBookId;
}
/**
* @return Returns the strBookName.
*/
public String getStrBookName() {
return strBookName;
}
/**
* @param strBookName The strBookName to set.
*/
public void setStrBookName(String strBookName) {
this.strBookName = strBookName;
}
}

IdIncrementExample.java

package sampack;


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


public class IdIncrementExample {
public static void main
(String[] args) {
Session session = null;

try{

SessionFactory sessionFactory =
new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();

org.hibernate.Transaction tx =
session.beginTransaction();

//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Book object into database..");
Book book = new Book();
book.setStrBookName("Hibernate Tutorial");
session.save(book);
System.out.println("Book object persisted to the database.");
tx.commit();
session.flush();
session.close();
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
}

}
}

Book.hbm.xml

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


<hibernate-mapping>
<class name="roseindia.tutorial.hibernate.Book" table="book">
<id name="lngBookId" type="long" column="id" >
<generator class="increment"/>
</id>

<property name="strBookName">
<column name="bookname" />
</property>
</class>
</hibernate-mapping>

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.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/abc</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="Book.hbm.xml"/>
</session-factory>
</hibernate-configuration>



I am getting an error for the line--

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

Please help..

Thanks in advance...


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.