0
0    [main] INFO  org.hibernate.cfg.Environment  - Hibernate 3.2.1
**strong text**15   [main] INFO  org.hibernate.cfg.Environment  - hibernate.properties not found
**strong text**15   [main] INFO  org.hibernate.cfg.Environment  - Bytecode provider name : cglib
**strong text**46   [main] INFO  org.hibernate.cfg.Environment  - using JDK 1.4 java.sql.Timestamp handling
**strong text**269  [main] INFO  org.hibernate.cfg.Configuration  - configuring from resource: hibernate.cfg.xml
**strong text**269  [main] INFO  org.hibernate.cfg.Configuration  - Configuration resource: hibernate.cfg.xml
**strong text**691  [main] ERROR org.hibernate.util.XMLHelper  - Error parsing XML: hibernate.cfg.xml(1) The processing instruction target matching "[xX][mM][lL]" is not allowed.
**strong text**Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at com.javatpoint.mypackage.StoreData.main(StoreData.java:15)
Caused by: org.dom4j.DocumentException: Error on line 1 of document  : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)

i have the above error when try to run storedata.java file.i am new to hibernate so please help me

Employee.java

package com.javatpoint.mypackage;
public class Employee {
private int id;  
private String firstName,lastName;  
public int getId() {  
return id; 
}
public void setId(int id) {  
this.id = id;  
enter code here
}
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;  
}  
}

StoreData.java

package com.javatpoint.mypackage;



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

   public class StoreData {  
   public static void main(String[] args) {  

   //creating configuration object  
   Configuration cfg=new Configuration();  
   cfg.configure("hibernate.cfg.xml");
   //populates the data of             the         configuration file  

    //creating seession factory object  
    SessionFactory factory=cfg.buildSessionFactory();  

//creating session object  
Session session=factory.openSession();  

//creating transaction object  
Transaction t=session.beginTransaction();  

Employee e1=new Employee();  
e1.setId(115);  
e1.setFirstName("sonoo");  
e1.setLastName("jaiswal");  

session.persist(e1);//persisting the object  

t.commit();//transaction is committed  
session.close();  

System.out.println("successfully saved");  

}  
}

employee.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="com.javatpoint.mypackage.Employee" table="emp1000">  
  <id name="id">  
   <generator class="assigned"></generator>  
   </id>  

<property name="firstName"></property>  
<property name="lastName"></property>  

 </class>  

</hibernate-mapping>  

hibernate.cfg.xml

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

    <session-factory>  
        <property name="hbm2ddl.auto">update</property>  
property name="hbm2ddl.auto">update</property>  
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>  
        <property name="connection.url">jdbc:mysql://localhost:3306/SampleDB</property>  
        <property name="connection.username">root</property>  
        <property name="connection.password">anbu</property>  
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>  
<mapping resource="employee.hbm.xml"/>  
    </session-factory>  

</hibernate-configuration>  

log4j.properties

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.

log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.

log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x 
-         %m%n**strong text**

i have inserted all the necessary jar files for hibernate and configure mysql correctly.

          `      
Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49
luvking
  • 61
  • 6

1 Answers1

0

Friends my problem solved and it excuted very well.i made a change in "hibernate.cfg.xml" file.here the changes are

<?xml version="1.0"?> 

instead of

<?xml version="1.0" encoding="UTF-8"?>
luvking
  • 61
  • 6
  • Your answer makes no sense given that UTF-8 is already the default encoding. If this did resolve your problem, it would have been because you inadvertently [removed leading visible or invisible characters before the XML declaration](http://stackoverflow.com/questions/19889132/error-the-processing-instruction-target-matching-xxmmll-is-not-allowed). – kjhughes Mar 23 '16 at 00:10