I am making a simple hibernate program. And I get this error. I am using a Mac and Eclipse Framework for this.
Exception in thread "main" org.hibernate.HibernateException: Error accessing stax stream
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:107)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:65)
at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:57)
at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)
at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at driver.main(driver.java:12)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Premature end of file.
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652)
at java.xml/com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:276)
at org.hibernate.boot.cfgxml.internal.JaxbCfgProcessor.unmarshal(JaxbCfgProcessor.java:103)
... 5 more
From the driver.java , I wish to make changes to the Database using Hibernate. I am not aware of the errors.
I am using an object of the employee class in driver.java.
Here is the employee.java
public class employee
{
private String name;
private int Eid;
private String city;
employee(){}
//getters
public String getName()
{
return this.name;
}
public int getEid()
{
return this.Eid;
}
public String getCity()
{
return this.city;
}
//setters
public void setEid(int a)
{
this.Eid=a;
}
public void setName(String s)
{
this.name=s;
}
public void setCity(String s)
{
this.city=s;
}
}
Driver .java
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class driver {
public static void main(String[] args)
{
Configuration conf = new Configuration();
conf.configure("/Users/ronin/Desktop/Hibernate/employee.hbm.xml");
SessionFactory sf = conf.buildSessionFactory();
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
employee e = new employee();
e.setEid(34);
e.setName("Robin");
e.setCity("Patiala");
s.persist(e);
tx.commit();
s.close();
}
}
employee.hbm.xml file
<?xml version = "1.0" encoding = "utf-8"?>
<hibernate-mapping>
<class name = "employee" table = "employee">
<id name = "id" type = "int" column = "id">
<generator class="native"/>
</id>
<property name = "name" column = "name" type = "string"/>
<property name = "city" column = "city" type = "string"/>
<property name = "Eid" column = "id" type = "int"/>
</class>
</hibernate-mapping>
hibernate, cfg.xml file
<?xml version='1.0' encoding='UTF-8'?>
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://localhost:3306</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<mapping resource="employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>