接上面,错误信息如下:%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: An association from the table OrderDetail refers to an unmapped class: com.onlineshop.pojo.Order
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1252)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at com.onlineshop.hibernate.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
at com.onlineshop.hibernate.TestDemo.testSession(TestDemo.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)请问各位这是怎么个问题..搞了半天都没搞出来...
最后问个很白的问题..在这里发帖..咋把代码放到一个类似框框的东西里..很起来貌似很规范..

解决方案 »

  1.   

    仔细检查下你的配置文件,看看你的hibernate的配置文件是否和你的pojo类的属性写的相同,你报错就是无法创建sessionFactory啊,你自己检查下
      

  2.   

    2楼的错误信息不对...貌似不能编辑..大家先帮我解决一下Could not parse mapping document from resource  
    这个问题..我用的是Hibernate+struts2.0开发的!~谢谢了!
      

  3.   


    开始我也是这么想的,我看了一下,貌似没啥问题,我利用这个hbm建表都没问题,但是一用到HibernateSessionFactory就出问题,我看了一下HibernateSessionFactory代码据我分析应该是一个静态代码块加载的时候出的异常static {
         try {
    configuration.configure(configFile);
    sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
    System.err
    .println("%%%% Error Creating SessionFactory %%%%");
    e.printStackTrace();
    }
        }
    我个人认为是在sessionFactory = configuration.buildSessionFactory();这句出的异常...
    就是不知道为什么...
      

  4.   

    我终于找到问题的关键了,在Order中有一个叫bNumber的属性,如果把大写N,就会报错.提示无法找到相应的get方法,无法解析该文件,改成小写的就不会出现这个问题.
    但是对应的set和get方法我都是用MyEcplise生成的,应该不会出问题,但是为什么会报错呢..很诡异..