Java – hibernate tutorial – where to place the mapping file?
I'm here to focus on Hibernate, an interesting tutorial: http://www.tutorialspoint.com/hibernate/hibernate_native_sql.htm
However, this tutorial ignores the location of these files I am using the folder structure of the basic Maven project
The folder structure is as follows:
foo └───src └───main ├───java │ └───org │ └───me │ └───bar │ └───[all my java source-files here] └───resources ├───hibernate.cfg.xml └───hiber └───Employee.hbm.xml
If ASCII art is not obvious, the folder main has the same level of Java and resources (Editor: now.)
Where should the mapping file (employee. HBM. XML) be placed? This file is referenced in the configuration file (hibernate. CFG. XML)
Thank you for reading this article
to greet,
Solution
You should put "hibernate. CFG. XML" under "/ SRC / main / resources"
According to the directory structure you provided, it should be like this;
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
You should be in hibernate cfg. All model files are referenced / mapped in the XML file, as shown below;
<mapping resource="org/me/bar/Employee.hbm.xml"/> <mapping resource="org/me/bar/Customer.hbm.xml"/>
You can also check and capture my project folder;