当前位置: 代码迷 >> Java Web开发 >> 关于Hibernate应射错误
  详细解决方案

关于Hibernate应射错误

热度:316   发布时间:2007-07-25 16:16:55.0
关于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  

----------------解决方案--------------------------------------------------------

程序代码:


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;
}

}


----------------解决方案--------------------------------------------------------
没找到com/chen/dao/config/droit.hbm.xml这个映射文件吧……
----------------解决方案--------------------------------------------------------

不是这个原因


----------------解决方案--------------------------------------------------------
上面这个问题解决了 但是又出现这个异常
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
----------------解决方案--------------------------------------------------------
<?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编辑过]


----------------解决方案--------------------------------------------------------
你在1楼的时候没有这个配置文件吧……现在怎么突然冒出来了
----------------解决方案--------------------------------------------------------
  相关解决方案