【问题标题】:hibernate.cfg.xml not found by Play FrameworkPlay Framework 未找到 hibernate.cfg.xml
【发布时间】:2013-01-24 10:21:00
【问题描述】:

我是 Play 框架的新手。我正在将一个项目从 struts2 迁移到使用 Hibernate for ORM 的 Play。我有一个名为 HibernateConfig 的单例类,它加载休眠配置,这是我得到以下错误的地方。

 In C:\Users\user\IdeaProjects\projectname\app\data\HibernateConfig.java at line 27. [HibernateException: /hibernate.cfg.xml not found] 
   private static SessionFactory sessionFactory;


  private HibernateConfig (){}

23  public static SessionFactory getSessionFactory ()
24  {

25      if (sessionFactory == null)
26      {

27          sessionFactory = new Configuration    ().configure().buildSessionFactory();
28          return sessionFactory;
29      }
30      else

 31         return sessionFactory;
  }

这是我的项目结构的样子:

应用程序 -> 控制器 -> 应用程序控制器类
应用程序 -> 模型 -> 模型类
应用程序 -> 数据 -> HibernateConfig.java
应用程序 -> 视图 -> html 文件
应用程序->hibernate.cfg.xml

应用程序.conf

数据库配置

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/dbname"
db.default.user=root
db.default.password=""

我知道问题是当我调用 new Configuration ().configure().buildSessionFactory() 时没有找到 hibernate.cfg.xml,但我不知道它必须放在 Play 中的哪个位置才能访问。 (你们能不能也批评一下我的做法,如果我做错了,请告诉我)

【问题讨论】:

    标签: java hibernate playframework-2.0


    【解决方案1】:

    将 hibernate.cfg.xml 文件添加到 conf 文件夹的根目录,这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 2012-01-02
      • 2011-06-23
      • 2015-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-23
      • 1970-01-01
      相关资源
      最近更新 更多