简体   繁体   English

使用Play Framework 1.2.5的Hibernate 3.2.5

[英]Hibernate 3.2.5 with Play Framework 1.2.5

I am trying to use Hibernate 3.2.5 with Play framework 1.2.5 我正在尝试将Hibernate 3.2.5与Play框架1.2.5一起使用

In Hibernate I am having two files: 在Hibernate中,我有两个文件:

1) cfg.xml file (containing the db config details along with some additional properties 2) hbm.xml file (containing the mapping between the java bean and the db table 1)cfg.xml文件(包含数据库配置详细信息以及一些其他属性 2)hbm.xml文件(包含Java bean与db表之间的映射

For getting connected to the oracle 10g db, I am providing the db details in the application.config files like this and the connection is successful also when I start the server: 为了连接到oracle 10g db,我在像这样的application.config文件中提供了db详细信息,并且在启动服务器时连接也成功了:

db.url=jdbc:oracle:thin:@localhost:1521/orcl
db.driver=oracle.jdbc.OracleDriver
db.user=system
db.pass=tiger

I want to know Where will I place the hbm.xml file (for mapping details) and the cfg.xml file for the remaining properties other than db connecion details? 我想知道如何将hbm.xml文件(用于映射详细信息)和cfg.xml文件放置在除db连接详细信息之外的其余属性上?

Please let me know about this. 请让我知道这一点。

Regards, 问候,

Starting from the root directory of your application: 从应用程序的根目录开始:

  • the hibernate.cfg.xml must be placed inside the app directory hibernate.cfg.xml必须放置在app目录中
  • the mapping files (the hbm files) where your models classes are defined, usually inside the app/models/ directory 定义模型类的映射文件( hbm文件),通常在app/models/目录中

Inside your hibernate.cfg.xml the mapping attributes should be something like: 在您的hibernate.cfg.xmlmapping属性应该类似于:

<mapping class="models.yourHmbFile1"/>
<mapping class="models.yourHmbFile2"/>

Btw, I find easy to use the hibernate annotations instead of the hbm - xml mapping. 顺便说一句,我发现易于使用休眠注释而不是hbm-xml映射。 Easier to write and to mantain. 易于编写和维护。

If you prefer to annotate your model classes, you can delete the hbm files and directly map your annotated classes in your hibernate.cfg.xml . 如果您希望对模型类进行注释,则可以删除hbm文件,并直接在hibernate.cfg.xml映射您的注释类。

In the application.conf you've to specify the data you have already added: application.conf您必须指定已经添加的数据:

db.url=jdbc:oracle:thin:@localhost:1521/orcl
db.driver=oracle.jdbc.OracleDriver
db.user=system
db.pass=tiger

Also in the hibernate.cfg.xml you need to specify the connection data: 同样在hibernate.cfg.xml您需要指定连接数据:

<property name="hibernate.dialect">...</property>
  <property name="hibernate.connection.driver_class">...</property>
  <property name="hibernate.connection.url">...</property>
  <property name="hibernate.connection.username">...</property>
  <property name="hibernate.connection.password">...</property>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM