techdow_hepalink 2008-10-03 10:53
浏览 234
已采纳

hibernate 日志异常

最近学习hibernate,看书感觉可以,实际操作怎么就那么难呢!
我用的是:hibernate3.2 eclipse3.3 (没有Myeclipse插件) Mysql6.0
一:main()函数
package org.first;
import org.hibernate.*;
import org.hibernate.cfg.*;

public abstract class FirstM {

/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    Configuration conf=new Configuration().configure();
    SessionFactory sf=conf.buildSessionFactory();
    Session sess=sf.openSession();
    Transaction tx=sess.beginTransaction();
    FirstBean fb=new FirstBean();
    fb.setUserId(12);
    fb.setUserName("thmei123");
    sess.save(fb);
    tx.commit();
    sess.close();
}

}
二:持久化类:很简单,一个主键userId,和一个属性userName;
public class FirstBean {

    private int userId;
    private String userName;
    public void setUserId(int userId)
    {
        this.userId=userId;
    }
    public int getUserid()
    {
        return this.userId;
    }
    public void setUserName(String userName)
    {
        this.userName=userName;
    }
    public String getUserName()
    {
        return this.userName;
    }

}
三:影射文件和配置文件:
1:<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">








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


org.gjt.mm.mysql.Driver
thmei123
jdbc:mysql://localhost/user
root
org.hibernate.dialect.MySQLDialect
20
1
5000
100
3000
2
true


说明;在主函数main()中运行后提示:
Exception in thread "main" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.first.FirstM.main(FirstM.java:12)
Caused by: java.lang.ClassNotFoundException: org.dom4j.DocumentException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)

提示的是要文件:
log4j-1.2.11.jar 和commons-logging-1.0.4.jar
这两个jar文件我都拷贝到了SRC下面了,也不可以阿

在网上查询说的是好像main()函数中不可以用日志文件,

希望大家帮我了,

另外 请大家给我一个详细的例子吧,最好是web工程的和java工程 各一个例子,

同时天涯沦落人啊!!
[b]问题补充:[/b]
谢谢 楼上兄弟的给你资料和建议,我现在除了拷贝了log4j-1.2.11.jar 和commons-logging-1.0.4.jar 这两个文件外,还在hibernate下拷贝了一个log4j.property的属性文件,都放置到了src下面,但是现在又出下面错误:

22:11:54,599 INFO Environment:514 - Hibernate 3.2.6
22:11:54,619 INFO Environment:547 - hibernate.properties not found
22:11:54,629 INFO Environment:681 - Bytecode provider name : cglib
22:11:54,639 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
22:11:54,850 INFO Configuration:1432 - configuring from resource: /hibernate.cfg.xml
22:11:54,850 INFO Configuration:1409 - Configuration resource: /hibernate.cfg.xml
22:11:55,501 INFO Configuration:559 - Reading mappings from resource : hib.hbm.xml
22:11:56,212 INFO HbmBinder:300 - Mapping class: FirstBean -> student
org.hibernate.InvalidMappingException: Could not parse mapping document from resource hib.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:575)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1593)

其中:
一:22:11:54,619 INFO Environment:547 - hibernate.properties not found
提示没有找到hibernate.properties 是怎么会事?我已经放置hibernate.properties,这个文件不是自己写,因为我不会写,就在hibernate下拷贝的一个,请大家给出建议,谢谢

二:org.hibernate.InvalidMappingException: Could not parse mapping document from resource hib.hbm.xml
这个实际上是提示没有找到hib.hbm.xml映射文件,我很是奇怪,无论我怎么修改的映射路径,都是不可以的!请大家帮助!!

学习中,望大家指点 谢谢

  • 写回答

1条回答 默认 最新

  • sptzone 2008-10-03 21:39
    关注

    [code="java"] org/dom4j/DocumentException [/code]这个提示需要的包是
    dom4j jar包

    DocumentException出现的原因是因为解析XML时出错。

    [url]http://makeitjoy.iteye.com/blog/244225[/url]

    推荐你可以先看看前面几章的实例。虽然是书籍里面的使用Hibernate2.0的,但是原理基本上是一样的。

    [url]http://www.javaresearch.org/article/38986.htm[/url]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧