使用hibernate做的一个最简单的例子,运行提示出错, 帮助看一下.(100分)

  • 主题发起人 主题发起人 唐太宗
  • 开始时间 开始时间

唐太宗

Unregistered / Unconfirmed
GUEST, unregistred user!
//Areas.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="House.Areas"
table="Areas"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="ID"
type="java.lang.String"
>
<generator class="assigned">
</generator>
</id>
<property
name="mc"
type="java.lang.String"
update="true"
insert="true"
column="mc"
/>
<property
name="memo"
type="java.lang.String"
update="true"
insert="true"
column="memo"
/>

</class>
</hibernate-mapping>
 
Areas.java
/*
* Created on 2003-7-6
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package House;
import java.util.HashSet;
import java.util.Set;
/**
* @hibernate.class
* table="USER"
*/
public class Areas {
private String _id;
private String _mc;
private String _memo;

private Set _posts;

private Areas() {}

public Areas(String id) {
_id = id;
}

public String getId() {
return _id;
}
private void setId(String id) {
_id = id;
}

public String getMc() {
return _mc;
}
public void setMc(String string) {
_mc = string;
}

public String getMemo() {
return _memo;
}
public void setMemo(String string) {
_memo = string;
}
}

 
//hibernate.properties
## Oracle
hibernate.dialect net.sf.hibernate.dialect.OracleDialect
hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
hibernate.connection.username tempuser
hibernate.connection.password 123
hibernate.connection.url jdbc:oracle:thin:@hostname:1521:dbname
 
//TestAreas.java
import House.*;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;

public class TestAreas
{
public static void main(String args[]) throws Exception
{
Configuration cfg = new Configuration().addClass(Areas.class);
SessionFactory sessions = cfg.buildSessionFactory();
new SchemaExport(cfg).create(true, true);
Session session = sessions.openSession();
Areas areas = new Areas("ftbmj");
session.save(areas);
session.flush();
session.close();
}
}
 
//出错信息

2003-10-12 20:15:09 net.sf.hibernate.cfg.Environment <clinit>
信息: Hibernate 2.0 final
2003-10-12 20:15:09 net.sf.hibernate.cfg.Environment <clinit>
信息: loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.query.imports=net.sf.hibernate.test, net.sf.hibernate.eg, hibernate.connection.username=HBEZWWL, hibernate.connection.url=jdbc:oracle:thin:@kx-39m37dhb9umb:1521:HBFT, hibernate.connection.password=2001419, hibernate.statement_cache.size=25, hibernate.connection.pool_size=1}
2003-10-12 20:15:09 net.sf.hibernate.cfg.Environment <clinit>
信息: using java.io streams to persist binary types
2003-10-12 20:15:09 net.sf.hibernate.cfg.Environment <clinit>
信息: using CGLIB reflection optimizer
2003-10-12 20:15:10 net.sf.hibernate.cfg.Environment <clinit>
信息: JVM proxy support: true
2003-10-12 20:15:10 net.sf.hibernate.cfg.Configuration addClass
信息: Mapping resource: House/Areas.hbm.xml
2003-10-12 20:15:12 net.sf.hibernate.util.XMLHelper$ErrorLogger error
严重: Error parsing XML: XML InputStream(48)
org.xml.sax.SAXParseException: The element type "class" must be terminated by the matching end-tag "</class>".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(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.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(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.DTDConfiguration.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:252)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:286)
at TestAreas.main(TestAreas.java:13)
2003-10-12 20:15:12 net.sf.hibernate.cfg.Configuration addInputStream
严重: Could not configure datastore from input stream
org.dom4j.DocumentException: Error on line 48 ofdo
cument : The element type "class" must be terminated by the matching end-tag "</class>". Nested exception: The element type "class" must be terminated by the matching end-tag "</class>".
at org.dom4j.io.SAXReader.read(SAXReader.java:355)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:286)
at TestAreas.main(TestAreas.java:13)
Nested exception:
org.xml.sax.SAXParseException: The element type "class" must be terminated by the matching end-tag "</class>".
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:252)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:286)
at TestAreas.main(TestAreas.java:13)
Hit uncaught exception net.sf.hibernate.MappingException
 
请大家都发表看法呀, 提提建议,
 
不懂,建议你到hibernate中文论坛去问问,hibernate问题不到它的论坛去问太可惜了:)
http://forum.hibernate.org.cn/index.php?sid=d99bafc621553922ab72405732efecf5
 
xml解析有问题
写xml时要特小心,我曾试过一个空格调了半天:(
 
没搞过 来看看中。。。。
 
多人接受答案了。
 
后退
顶部