hibernate.cfg.xml在解析时出错,请高手指点

cruelmurder 2006-12-20 06:44:14
hibernate.cfg.xml的内容如下,
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-configuration>
<session-factory>

<property name="connection.username">root</property>

<property name="connection.url">jdbc:mysql://localhost:3306/study</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.password"></property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

<mapping resource="study.hbm.xml"/>

</session-factory>
</hibernate-configuration>


测试类如下:
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;


import java.io.*;
public class Test{
public static void main(String[] args)
{
System.out.print("begin\n");
try{
System.out.print("begin sessionFactory\n");
// SessionFactory sf = new Configuration().configure("study.hbm.xml").buildSessionFactory();
SessionFactory sf = new Configuration().configure().buildSessionFactory();


Session session = sf.openSession();

Transaction tx = session.beginTransaction();
for(int i=0;i<10;i++)
{
System.out.print("OK");
study stu =new study();

stu.setUserid("userid"+i);
stu.setPassword("password"+i);
session.save(stu);
}
tx.commit();
session.close();
}
catch(HibernateException e){

e.printStackTrace();
}

System.out.print("end");
}

}
程序执行行报如下错误,

D:\antproject>ant run
Buildfile: build.xml

init:

build:

run:
[java] begin
[java] begin sessionFactory
[java] 18:43:39,214 INFO Environment:483 - Hibernate 2.1.8
[java] 18:43:39,224 INFO Environment:517 - loaded properties from resource
hibernate.properties: {hibernate.connection.driver_class=org.hsqldb.jdbcDriver,
hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=n
et.sf.hibernate.cache.EhCacheProvider, hibernate.cache.use_query_cache=true, hib
ernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect
, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hiber
nate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.poo
l_alias=pool1, hibernate.connection.username=sa, hibernate.cache.region_prefix=h
ibernate.test, hibernate.connection.url=jdbc:hsqldb:., hibernate.connection.pass
word=, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=
1}
[java] 18:43:39,234 INFO Environment:542 - using java.io streams to persis
t binary types
[java] 18:43:39,234 INFO Environment:543 - using CGLIB reflection optimize
r
[java] 18:43:39,234 INFO Environment:572 - using JDK 1.4 java.sql.Timestam
p handling
[java] 18:43:39,244 INFO Configuration:909 - configuring from resource: /h
ibernate.cfg.xml
[java] 18:43:39,244 INFO Configuration:881 - Configuration resource: /hibe
rnate.cfg.xml
[java] 18:43:39,845 ERROR Configuration:971 - problem parsing configuration
/hibernate.cfg.xml
[java] org.dom4j.DocumentException: Invalid byte 2 of 2-byte UTF-8 sequence
. Nested exception: Invalid byte 2 of 2-byte UTF-8 sequence.
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:358)
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.
java:967)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.ja
va:911)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.ja
va:897)
[java] at Test.main(Unknown Source)
[java] Nested exception:
[java] java.io.UTFDataFormatException: Invalid byte 2 of 2-byte UTF-8 seque
nce.
[java] at org.apache.xerces.impl.io.UTF8Reader.invalidByte(Unknown Sour
ce)
[java] at org.apache.xerces.impl.io.UTF8Reader.read(Unknown Source)
[java] at org.apache.xerces.impl.XMLEntityScanner.load(Unknown Source)
[java] net.sf.hibernate.HibernateException: problem parsing configuration/h
ibernate.cfg.xml
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.
java:972)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.ja
va:911)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.ja
va:897)
[java] at Test.main(Unknown Source)
[java] Caused by: org.dom4j.DocumentException: Invalid byte 2 of 2-byte UTF
-8 sequence. Nested exception: Invalid byte 2 of 2-byte UTF-8 sequence.
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:358)
[java] at org.apache.xerces.impl.XMLEntityScanner.scanData(Unknown Sour
ce)
[java] at org.apache.xerces.impl.XMLScanner.scanComment(Unknown Source)

[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanCom
ment(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$Fragmen
tContentDispatcher.dispatch(Unknown Source)
[java] at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDoc
ument(Unknown Source)
[java] at org.apache.xerces.parsers.XML11Configuration.parse(Unknown So
urce)
[java] at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Sour
ce)
[java] at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
[java] at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Sou
rce)
[java] at org.dom4j.io.SAXReader.read(SAXReader.java:339)
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.
java:967)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.ja
va:911)
[java] at net.sf.hibernate.cfg.Configuration.configure(Configuration.ja
va:897)
[java] at Test.main(Unknown Source)
[java] at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.
java:967)
[java] ... 3 more
[java] end

BUILD SUCCESSFUL
Total time: 3 seconds
请高手指点一下,这是什么问题?本人不胜感激!!!!
...全文
252 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
assed 2006-12-20
文件最前面几个
<?xml version='1.0' encoding='UTF-8'?>

try
回复
相关推荐
发帖
Java EE
创建于2007-09-28

6.6w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2006-12-20 06:44
社区公告
暂无公告