我的目录
hibernatest
|--src
|--classes

解决方案 »

  1.   

    有两种放法:
    1将hibernate.cfg.xml与student.hbm.xml都放在WEB-INF/classes目录下,看你给出的配置文件应该这样放
    2将hibernate.cfg.xml放在WEB-INF/classes目录下,而将student.hbm.xml与它的类文件放在同一个目录中,此时,在hibernate.cfg.xml中配置student.hbm.xml时用带目录的文件名(这里目录是指student类所在的包的目录。
      

  2.   

    我照楼上说的改了一下我的hibernate.cfg.xml这个是我的hibernate.cfg.xml<?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"><hibernate-configuration>
        <session-factory>
            <property name="connection.username">scott</property>
    <property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:WP</property>
    <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
    <property name="connection.password">tiger</property>
            <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property><mapping resource="hibernatetest/student.hbm.xml"/>
            </session-factory>
    </hibernate-configuration>
    我的目录我的目录
    hibernatest
    |--src
    |--classes
    |  |
    |  |__hibernate.cfg.xml
    |  |__hibernatetest
    |     |___student.hbm.xml可是还是不行还是抱了错org.hibernate.MappingException: Could not read mappings from resource: hibernatetest/Student.hbm.xml
    请问怎么解决啊!我这个问题搞了几天 郁闷!!!
      

  3.   

    还有log4这个文件是和hibernate放在同一级的吗
      

  4.   

    我的完整错误:11:45:50,921  INFO Environment:479 - Hibernate 3.1.211:45:50,937  INFO Environment:509 - hibernate.properties not found11:45:50,937  INFO Environment:525 - using CGLIB reflection optimizer11:45:50,953  INFO Environment:555 - using JDK 1.4 java.sql.Timestamp handling11:45:51,062  INFO Configuration:1308 - configuring from resource: /hibernate.cfg.xml11:45:51,062  INFO Configuration:1285 - Configuration resource: /hibernate.cfg.xml11:45:51,453  INFO Configuration:469 - Reading mappings from resource: hibernatetest/Student.hbm.xml11:45:51,531 ERROR XMLHelper:61 - Error parsing XML: XML InputStream(10) The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".org.hibernate.MappingException: Could not read mappings from resource: hibernatetest/Student.hbm.xml
      

  5.   

    你的Student.hbm.xml代码贴出来看一下
      

  6.   

    <mapping resource="hibernatetest/student.hbm.xml"/>Could not read mappings from resource: hibernatetest/Student.hbm.xml文件名字拼写有误.
      

  7.   

    的确,在java中大小写不要搞错。
      

  8.   

    我把大小写改了过来 还是不行啊!我的student.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">    <hibernate-mapping>
         <class name="Student" table="student">
    <property name="id" column="id"/>
         <property name="name" column="name"/>
         </class>
        </hibernate-mapping>
      

  9.   

    急死了学java快半年了 没这么郁闷过
      

  10.   

    The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
    --------------------------------
    很初级的错误,配置文件写错了
        <hibernate-mapping>
         <class name="Student" table="student">
            <id name="id">
                <generator class="uuid.hex"/>
            </id>
         <property name="name" column="name"/>
         </class>
        </hibernate-mapping>
    这里有hibernate3.1.2的中文文档,多看看
    http://www.redsaga.com/hibernate-ref/3.1.2/zh-cn/html_single/
      

  11.   

    <generator class="uuid.hex"/>的话,
    类Student的id必须为String,表Student的列Id必须为varchar(32)
      

  12.   

    就是说每个xxx.hbm.xml文件中都要有<id>这个节点?我表中要是没有id这个字段怎么办呢?还有uuid.hex是什么策略呢?我的表结构
    id number(4)
    name varchar2 (20)这样的话我应该怎么改呢
      

  13.   

    我照你的改了下我的Student.java:
    package hibernatetest;public class Student
    {
        private String id;
        private String name;
        public Student()
        {
        }    public String getId()
        {
            return id;
        }    public String getName()
        {
            return name;
        }    public void setId(String id)
        {
            this.id = id;
        }    public void setName(String name)
        {
            this.name = name;
        }
    }
    Student.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">
    <hibernate-mapping>
         <class name="Student" table="student">
            <id name="id">
                <generator class="uuid.hex"/>
            </id>
         <property name="name" column="name"/>
         </class>
        </hibernate-mapping>还是报了个错:
    org.hibernate.MappingException: Could not read mappings from resource: hibernatetest/Student.hbm.xml at org.hibernate.cfg.Configuration.addClass(Configuration.java:506) at hibernatetest.InsertData.main(InsertData.java:17)Caused by: org.hibernate.MappingException: class Student not found while looking for property: id at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:80) at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276) at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:410) at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:343) at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282) at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153) at org.hibernate.cfg.Configuration.add(Configuration.java:386) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427) at org.hibernate.cfg.Configuration.addClass(Configuration.java:503) ... 1 moreCaused by: java.lang.ClassNotFoundException: Student at java.net.URLClassLoader$1.run(URLClassLoader.java:199) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:187) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:141) at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108) at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:76) ... 9 more18:44:51,296  INFO HbmBinder:309 - Mapping class: Student -> student
      

  14.   

    Caused by: java.lang.ClassNotFoundException: Student
    ---
    <class name="Student" table="student">
    name要写全:hibernatetest.Student
      

  15.   

    真是晕了 还是出不来啊~~~~我急死了
    可能是我刚才改了下~~~~还是有问题~~~~我的Student类的id也是String了啊

    package hibernatetest;public class Student
    {
        private String  id;
        private String name;
        public Student()
        {
        }    public String getId()
        {
            return id;
        }    public String getName()
        {
            return name;
        }    public void setId(String id)
        {
            this.id = id;
        }    public void setName(String name)
        {
            this.name = name;
        }
    }我的Student.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">
    <hibernate-mapping>
         <class name="hiberbatetest.Student" table="student">
            <id name="id" type="String">
                <generator class="uuid.hex"/>
            </id>
         <property name="name" column="name"/>
         </class>
        </hibernate-mapping>
    可就是还报错 我的数据库是ORACLE
    创建表:
     create table student
     (id varchar(4),
     name varchar(20)
     )报的异常::org.hibernate.MappingException: Could not read mappings from resource: hibernatetest/Student.hbm.xml at org.hibernate.cfg.Configuration.addClass(Configuration.java:506) at hibernatetest.InsertData.main(InsertData.java:17)Caused by: org.hibernate.MappingException: class hiberbatetest.Student not found while looking for property: name at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:80) at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276) at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2138) at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2115) at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2005) at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:368) at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282) at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153) at org.hibernate.cfg.Configuration.add(Configuration.java:386) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427) at org.hibernate.cfg.Configuration.addClass(Configuration.java:503) ... 1 moreCaused by: java.lang.ClassNotFoundException: hiberbatetest.Student at java.net.URLClassLoader$1.run(URLClassLoader.java:199) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:187) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:141) at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108) at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:76) ... 11 more19:10:20,859  INFO HbmBinder:309 - Mapping class: hiberbatetest.Student -> student
      

  16.   

    不好意思 刚才student.hbm.xml的name写错了
    我改了下
    现在是这个错误org.hibernate.MappingException: Could not determine type for: String, for columns: [org.hibernate.mapping.Column(id)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266) at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253) at org.hibernate.mapping.RootClass.validate(RootClass.java:193) at org.hibernate.cfg.Configuration.validate(Configuration.java:984) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1169) at hibernatetest.InsertData.main(InsertData.java:19)
      

  17.   

    好了
    终于出来了!
    我的表结构有点问题刚才!我刚查询了一下
    我的id插入的是1
    怎么显示的是:
    ID
    ----------------------------------------------------------------
    NAME
    ----------------------------------------
    402881f40a26d488010a26d48aae0001
    h那么多字符 
    我想他显示为1怎么办?
    我插入几就显示数字几