I am creating a Hibernate application
package com.jlcindia.hibernate;
public class Customer {
private int cid;
private String cname;
private String emal;
private long phone;
private String city;
private double bal;
public Customer(){}
public Customer(String cname,String emal,long phone,String city,double bal){
this.cname=cname;
this.emal=emal;
this.phone=phone;
this.city=city;
this.bal=bal;
}
}
My application
package com.jlcindia.hibernate;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class Lab1A {
public static void main(String[] args) {
// TODO Auto-generated method stub
Transaction tx=null;
try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
tx=session.beginTransaction();
Customer cust=new Customer("sri","sri@jlc.com",1234,"blore",25000.0);
session.save(cust);
tx.commit();
session.close();
System.out.println("record inserted");
}
catch(Exception e){
e.printStackTrace();
if(tx!=null)
tx.rollback();
}
}}
Configuraton file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="username">system</property>
<property name="password">Srikant1</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/jlcindia/hibernate/Customer.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Mapping file
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping package="com.jlc.india.hibernate">
<class name="Customer" table="customers">
<id name="cid" column="cid" type="int">
<generator class="increment"/>
</id>
<property name="cname"/>
<property name="emal" column="emal"/>
<property name="phone" column="phone" type="long"/>
<property name="city" column="city" type="string"/>
<property name="bal" column="bal" type="double"/>
</class>
</hibernate-mapping>
But i am getting this error
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See
http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
at com.jlcindia.hibernate.Lab1A.main(Lab1A.java:11)
Caused by: org.dom4j.DocumentException: Error on line 30 of document : The markup in the document following the root element must be well-formed. Nested exception: The markup in the document following the root element must be well-formed.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
... 3 more