| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1115 人关注过本帖
标题:关于Hibernate应射错误
只看楼主 加入收藏
亮剑
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-10-18
收藏
 问题点数:0 回复次数:6 
关于Hibernate应射错误


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
\"-//Hibernate/Hibernate Configuration DTD 2.0//EN\"
\"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd\">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name=\"connection.username\">root</property>
<property name=\"connection.url\">
jdbc:mysql://localhost:3306/pop
</property>
<property name=\"dialect\">
net.sf.hibernate.dialect.MySQLDialect
</property>
<property name=\"myeclipse.connection.profile\">mysql</property>
<property name=\"connection.password\">1982</property>
<property name=\"connection.driver_class\">
com.mysql.jdbc.Driver
</property>
<property name=\"show_sql\">true</property>
<mapping resource=\"com/chen/dao/config/droit.hbm.xml\" />
<mapping resource=\"com/chen/dao/config/actor.hbm.xml\" />
<mapping resource=\"com/chen/dao/config/user.hbm.xml\" />
</session-factory>

</hibernate-configuration>




<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE hibernate-mapping PUBLIC \"-//Hibernate/Hibernate Mapping DTD 2.0//EN\" \"hibernate-mapping-2.0.dtd\" >
<hibernate-mapping>
<class name=\"com.chen.pojo.Actor\" table=\"actor\">
<id name=\"id\" column=\"id\" type=\"Integer\">
<generator class=\"increment\"></generator>
</id>
<property name=\"name\" column=\"droit_name\"></property>
<set name=\"droit\" cascade=\"all\">
<key column=\"droit_id\"></key>
<one-to-many class=\"com.chen.pojo.Droit\" />
</set>
</class>
</hibernate-mapping>




<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE hibernate-mapping PUBLIC \"-//Hibernate/Hibernate Mapping DTD 2.0//EN\" \"hibernate-mapping-2.0.dtd\" >
<hibernate-mapping>
<class name=\"com.chen.pojo.Actor\" table=\"actor\">
<id name=\"id\" column=\"id\" type=\"Integer\">
<generator class=\"increment\"></generator>
</id>
<property name=\"name\" column=\"droit_name\"></property>
<set name=\"droit\" cascade=\"all\">
<key column=\"droit_id\"></key>
<one-to-many class=\"com.chen.pojo.Droit\" />
</set>
</class>
</hibernate-mapping>



<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE hibernate-mapping PUBLIC \"-//Hibernate/Hibernate Mapping DTD 2.0//EN\" \"hibernate-mapping-2.0.dtd\" >
<hibernate-mapping>
<class name=\"com.chen.pojo.User\" table=\"user\">
<id name=\"id\" column=\"id\" type=\"Integer\">
<generator class=\"increment\"></generator>
</id>
<property name=\"name\" column=\"user_name\"></property>
<property name=\"password\" column=\"password\"></property>
<many-to-one name=\"actor\"
column=\"actor_id\"
class=\"com.chen.pojo.Actor\"
cascade=\"all\"
/>
</class>
</hibernate-mapping>

===================================报错误=====================

log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%
net.sf.hibernate.MappingException: Error reading resource: com/chen/dao/config/droit.hbm.xml

at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:339)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1018)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:974)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:902)
at com.chen.factory.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:48)
at com.chen.dao.UserDao.<init>(UserDao.java:19)
at com.chen.dao.test.UserTest.testAddUser(UserTest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: net.sf.hibernate.MappingException: org.dom4j.DocumentException: Stopping after fatal error: File \"hibernate-mapping-2.0.dtd\" not found. Nested exception: Stopping after fatal error: File \"hibernate-mapping-2.0.dtd\" not found.
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:296)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:336)
... 24 more
Caused by: org.dom4j.DocumentException: Stopping after fatal error: File \"hibernate-mapping-2.0.dtd\" not found. Nested exception: Stopping after fatal error: File \"hibernate-mapping-2.0.dtd\" not found.
at org.dom4j.io.SAXReader.read(SAXReader.java:358)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:286)
... 25 more

高人指点

[此贴子已经被作者于2007-7-25 16:20:30编辑过]

搜索更多相关主题的帖子: Hibernate 
2007-07-25 16:16
亮剑
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-10-18
收藏
得分:0 

程序代码:


public class Actor {
private Integer id;

private String name;

private HashSet droit;


public HashSet getDroit() {
return droit;
}

public void setDroit(HashSet droit) {
this.droit = droit;
}

public Integer getId() {
return id;
}

private void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

private void createDroit(String name) {
this.name = name;
}

}
=======================
public class Droit {
private Integer id;

private String name;

public Integer getId() {
return id;
}

private void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
======================
public class User {
private String id;

private String name;

private String password;

private Actor actor;

public Actor getActor() {
return actor;
}

public void setActor(Actor actor) {
this.actor = actor;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

}

2007-07-25 16:34
飘飘叶子
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:597
专家分:10
注 册:2005-8-17
收藏
得分:0 
没找到com/chen/dao/config/droit.hbm.xml这个映射文件吧……

向着软件工程师的目标前进!
2007-07-25 16:59
亮剑
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-10-18
收藏
得分:0 

不是这个原因

2007-07-25 17:03
亮剑
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-10-18
收藏
得分:0 
上面这个问题解决了 但是又出现这个异常
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%
net.sf.hibernate.MappingException: Error reading resource: com/chen/dao/config/droit.hbm.xml

at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:340)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:1027)
at net.sf.hibernate.cfg.Configuration.doConfigure(Configuration.java:983)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:911)
at com.chen.factory.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:48)
at com.chen.dao.hibernate.UserDao.<init>(UserDao.java:22)
at com.chen.dao.hibernate.test.UserTest.testAddUser(UserTest.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: net.sf.hibernate.MappingException: invalid mapping
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addResource(Configuration.java:337)
... 24 more
Caused by: org.xml.sax.SAXParseException: Document root element "hibernate-mapping", must match DOCTYPE root "hibernate-configuration".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:339)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:287)
... 25 more
2007-07-25 21:56
亮剑
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-10-18
收藏
得分:0 
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-mapping>
<class name="com.chen.pojo.Droit" table="droit">
<id name="id" column="id" type="Integer">
<generator class="increment"></generator>
</id>
<property name="name" column="droit_name" />
</class>
</hibernate-mapping>

这个配置文件有甚么问题

[此贴子已经被作者于2007-7-25 21:57:49编辑过]

2007-07-25 21:57
飘飘叶子
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:597
专家分:10
注 册:2005-8-17
收藏
得分:0 
你在1楼的时候没有这个配置文件吧……现在怎么突然冒出来了

向着软件工程师的目标前进!
2007-07-26 14:41
快速回复:关于Hibernate应射错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018410 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved