Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Servlet/JSP/JSF/JavaFX Script  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to postflat modethreaded modego to previous topicgo to next topicgo to back
作者 hibernate 入门问题 大哥们帮忙啊
198255nihao





发贴: 6
于 2007-05-11 10:18 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我怎么总是出现
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
.
.
.
Caused by: org.dom4j.DocumentException: Error on line 20 of document : Content is not allowed in trailing section. Nested Exception: Content is not allowed in trailing section

的异常啊

hibernate.cfg.xml 如下

<?xml version="1.0" encoding="GB2312"?>
<!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>
    <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
    <property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
    <property name="connection.url">jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=TEACHER</property>
    <property name="connection.username">sa</property>
    <property name="connection.password"/>
    <mapping resource="teach/Students.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

Students.hbm.xml 如下

<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="teach.Students" table="STUDENTS">
<property name="students_id" column="STUDENTS_ID" type="string" />
<property name="students_name" column="STUDENTS_NAME" type="string" />
<property name="students_class" column="STUDENTS_CLASS" type="string" />
</class>
</hibernate-mapping>

我用得是 hibernate 3

Students.java 如下

package teach;

import java.io.Serializable;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright Coffee 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Students implements Serializable{

private String students_class;
private String students_id;
private String students_name;
public Students() {
}
public String getStudents_class() {
return students_class;
}

public void setStudents_class(String students_class) {
this.students_class = students_class;
}

public void setStudents_name(String students_name) {
this.students_name = students_name;
}

public void setStudents_id(String students_id) {
this.students_id = students_id;
}

public String getStudents_id() {
return students_id;
}

public String getStudents_name() {
return students_name;
}

}

BusinessService.java 如下

package teach;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright Coffee 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class BusinessService {
public static SessionFactory sessionFactory;
static {
try {
Configuration config = new Configuration().configure();
sessionFactory = config.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
Session session = sessionFactory.openSession();
Transaction tx = null;
Students s = new Students();
s.setStudents_id("001");
s.setStudents_name("王一");
s.setStudents_class("一班");
try {
tx = session.beginTransaction();
session.save( s );
tx.commit();
} catch (Exception e) {
if (tx != null) {
// Something went wrong; discard all partial changes
tx.rollback();
}
throw e;
} finally {
// No matter what, close the session
session.close();
}
}
}


YuLimin edited on 2007-05-15 20:06


话题树型展开
人气 标题 作者 字数 发贴时间
3053 hibernate 入门问题 大哥们帮忙啊 198255nihao 4148 2007-05-11 10:18
2657 Re:hibernate 入门问题 大哥们帮忙啊 JiafanZhou 398 2007-05-11 17:00
2673 Re:hibernate 入门问题 大哥们帮忙啊 YuLimin 68 2007-05-15 20:07
2648 Re:hibernate 入门问题 大哥们帮忙啊 198255nihao 10 2007-05-16 19:52
2679 Re:hibernate 入门问题 大哥们帮忙啊 chengbd 28 2007-05-22 13:12

reply to postflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923