myeclipse出现Could not parse configuration: /hibernate.cf

J2EE 码拜 8年前 (2017-04-16) 1506次浏览
出现的几个错误,实在是不会弄
2016-10-13 19:18:34 org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-10-13 19:18:34 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.10.Final}
2016-10-13 19:18:34 org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
2016-10-13 19:18:34 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
2016-10-13 19:18:34 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
2016-10-13 19:18:34 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Exception in thread “main” org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2165)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2077)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2056)
at StudentTest.main(StudentTest.java:16)
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:2157)
… 3 more
这个是出现的错误,
hibernate.cfg.xml的代码如下(用IE打开没有显示错误,就是显示相应的代码)

     <?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver </property>   
            <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate</property>     
          <property name="hibernate.connection.username">root</property>   
          <property name="hibernate.connection.password">12345678</property>          
         <!--   <property name="hibernate.connection.pool.size">1</property> -->         
        <property name="hibernate.show_sql">true </property>   
     <!--   <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>   -->     
    <property name="connection.characterEncoding">UTF-8</property>            
       <!--    <property name="hbm2ddl.auto">update</property>   -->   
          <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect </property>          
          <mapping resource="com/hibernate/Student.hbm.xml"/> 
  </session-factory>   
  </hibernate-configurat

student.hbm.xml的代码如下(用IE打开没有显示错误,就是显示相应的代码)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.hibernate">
    <class name="Student">
      <id name="id"></id>
      <property name="name"></property>
      <property name="age"></property>
    </class>
</hibernate-mapping>

测试类

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.hibernate.Student;
public class StudentTest {
	public static void main(String[] args) {
		Student s=new Student();
		s.setName("sa");
		s.setAge(12);
		Configuration cf=new Configuration();
		SessionFactory sf=cf.configure().buildSessionFactory();
		Session session=sf.openSession();
		session.beginTransaction();
		session.save(s);
		session.getTransaction().commit();
		session.close();
		sf.close();

	}
}

student.java这个类就是一个get和set方法就不写了
完全是按着书上的来写的。就是出现错误实在是无力解决,,只能求帮助高手们了

解决方案

5

<class name=”Student”>
<id name=”id”></id>
<property name=”name”></property>
<property name=”age”></property>
</class>
 怎么没有column?

35

导入的包有问题,缺少一些包,hibernate3.jar,commons-collections.jar,加入这些包就可以

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明myeclipse出现Could not parse configuration: /hibernate.cf
喜欢 (0)
[1034331897@qq.com]
分享 (0)