本帖最后由 oMarlboro123456 于 2013-01-23 10:24:37 编辑

解决方案 »

  1.   

    Users.hbm.xml 配置文件有问题 ,仔细点写吧。
      

  2.   

    hibernate.cfg.xml
    这个文件你放在哪个目录下面的?
      

  3.   

    异常信息:Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
    把下面的信息换成你的hbm.xml开头部分
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
      

  4.   

    没问题阿,我用的是MyEclipse10.7+SQL2012,是不是我版本的问题啊
      

  5.   

    创建Configuration对象的时候、传入你配置文件的路径:
    Configuration conf = new Configuration().configure("/hibernate.cfg.xml");
      

  6.   


    默认就是src下面的,
    你hibernate的版本是多少?
    我记得以前有人发过帖子,hiberntate的版本不同,加载方式不同。
      

  7.   

    4.1.?
    几?
    4.1.8 不让用buildSessionFactory() 方法了
    这是4.1.8之后的方法:
     public static void main(String[] args) {
             
            Student s=new Student();
            s.setId(1);
            s.setName("penglei");
            s.setAge(25);
             
            Configuration config=new Configuration().configure();        
            ServiceRegistry sr=new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();         
            SessionFactory sf=config.buildSessionFactory(sr); 
            Session session=sf.openSession();
            session.beginTransaction();
            session.save(s);
            session.getTransaction().commit();
            session.close();
            sf.close();
             
        }最后发一下感叹,这是我半年前在CSDN上看到一个问题,半年后竟然能找到原帖子,百度真强大。!~
      

  8.   

    加载hibernate.cfg.xml的时候说你的hbm.xml找不到指定的文件!
    你得换一个3楼给出的dtd
      

  9.   

    Caused by: org.xml.sax.SAXParseException: Document root element "hibernate-configuration", must match DOCTYPE root "hibernate-mapping".
    现在变成介个了
      

  10.   

    你不要它自动生成, 手动去弄 eclipse有时候很坑爹的 
      

  11.   

    好像你的dtd最后多了一个空格!
      

  12.   

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ">
    把中间的空格去掉。