当前位置: 代码迷 >> Eclipse >> org.xml.sax.SAXException: System property org.xml.sax.driver not specified
  详细解决方案

org.xml.sax.SAXException: System property org.xml.sax.driver not specified

热度:571   发布时间:2016-04-23 14:20:33.0
hibernate如何配置啊?
HIBERNATE 就没有配置成功过。。很郁闷。。
最近出的错误是这个。。
请高手帮我看看
我装的是eclipse3.2
和myeclipse5.1
内含hibernate3.1




log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Warning: Caught exception attempting to use SAX to load a SAX XMLReader 
org.xml.sax.SAXException: System property org.xml.sax.driver not specified
Warning: Exception was: org.xml.sax.SAXException: System property org.xml.sax.driver not specified
Warning: I will print the stack trace then carry on using the default SAX parser
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)
at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83)
at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894)
at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715)
at org.dom4j.io.SAXReader.read(SAXReader.java:435)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1366)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
at dao.test.main(test.java:12)
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1376)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
at dao.test.main(test.java:12)
Caused by: org.dom4j.DocumentException: System property org.xml.sax.driver not specified Nested exception: System property org.xml.sax.driver not specified
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1366)
... 3 more


------解决方案--------------------
使用hibernate编程步骤
1,配置环境,加载hibernate的jar文件,以及连接数据库连接使用的jar文件,并配置CLASSPATH环境变量。
2,写hibernate所需的配置文件,hibernate.cfg.xml ,Xxxxx.hbm.xml
3,写POJO类
4,调用hibernate API。
1)使用Configuration对象的buildSessionFactory()方法创建SessionFactory对象
2)使用SessionFactory对象openSession()方法创建Session对象。
3)使用Session的相应方法来操作数据库,将对象信息持久化到数据库。


hibernate.cfg.xml中会设置数据库的连接信息,以及引用的其他文件的文件名,和一些其他的摄制。这个文件一般放在项目的根目录下。

在hibernate.cfg.xml的写法
<!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="show_sql">true</property><!--显示sql语句-->
 <property name="format_sql">true</property><!--使显示的sql语句格式化-->
 <property name="dialect">....</property><!--使用的数据库方言信息-->
<property name="connection.driver_class">....</property>
 <!--使用的数据库的驱动-->
 <property name="connection.url">....</property><!--连接数据库使用的url-->
<property name="connection.username">...</property>
 <!--连接数据库的用户名-->
 <property name="connection.password">...</property>
 <!--连接数据库的密码-->

 <mapping resource="xxx/xxxx/Xxxxxx.hbm.xml"/>
 <!--引入的映射对象的xml文件的全路径及文件名-->
 </session-factory>
</hibernate-configuration>


hibernate的映射类的XXXX.hbm.xml的写法

<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE hibernate-mapping PUBLIC 
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  相关解决方案