Hibernate教程-在哪里放置映射文件? [英] Hibernate Tutorial - Where to put Mapping File?

查看:108
本文介绍了Hibernate教程-在哪里放置映射文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里关注有关休眠的有趣教程: http://www.tutorialspoint.com /hibernate/hibernate_native_sql.htm

I am following this interesting tutorial on hibernate here: http://www.tutorialspoint.com/hibernate/hibernate_native_sql.htm

但是,本教程忽略了放置这些文件的位置.我正在使用基本Maven项目的文件夹结构.

This tutorial, however, neglects to mention where to put these files. I am using a folder structure of a basic Maven project.

文件夹结构如下:

foo
└───src
    └───main
        ├───java
        │   └───org
        │       └───me
        │           └───bar 
        │               └───[all my java source-files here]
        └───resources
            ├───hibernate.cfg.xml
            └───hiber
                └───Employee.hbm.xml

如果ASCII技术不明显,文件夹mainjavaresources处于同一级别. (现在是.)

The folder main has java and resources at the same level if this is not obvious by the ASCII art. ( now it is.)

映射文件(Employee.hbm.xml)应该放在哪里?该文件在配置文件(hibernate.cfg.xml)中引用.

Where should the mapping file (Employee.hbm.xml) go? The file is referenced in the configuration file (hibernate.cfg.xml).

谢谢您阅读本文.

此致

推荐答案

您应将" hibernate.cfg.xml "放在"/src/main/resources "下" 您应该将所有模型映射文件放在定义POJO模型类的目录下.

You should put the "hibernate.cfg.xml" under "/src/main/resources" You should put all the model-mapping files under the same directory that you define the POJO model classes.

根据您提供的目录结构,它应该像;

According to the directory structure that you've provided, it should be like;

foo
└───src
    └───main
        ├───java
        │   └───org
        │       └───me
        │           └───bar 
        │               └───[all your java Model source-files here]
        |                    Employee.java
        |                    Employee.hbm.xml
        |                    Customer.java
        |                    Customer.hbm.xml
        └───resources
            └───hibernate.cfg.xml

并且您应该像下面那样在 hibernate.cfg.xml 文件中引用/映射所有模型文件;

And you should reference/map all your Model files in your hibernate.cfg.xml file like below;

    <mapping resource="org/me/bar/Employee.hbm.xml"/>
    <mapping resource="org/me/bar/Customer.hbm.xml"/>

您也可以检查一下,捕获我的项目文件夹;

You can also check this out, a capture of my project folder;

这篇关于Hibernate教程-在哪里放置映射文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆