Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate Mapping File in Hibernate

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to generate Mapping files in Hibernate", the content is simple and easy to understand, organized clearly, I hope to help you solve doubts, let Xiaobian lead you to study and learn "how to generate Mapping files in Hibernate" this article bar.

In hibernate, each data table corresponds to an entity class, each entity class has a corresponding hbm.xml configuration file and you match, myeclipse actually has a MyEclipse Database Explorer view, which provides a built-in window for myeclipse to connect directly to the database, and through this window you can generate hibernate mapping files.

1. Right-click on the project and select the MyEclipse option to add Hibernate features to the app.

2. Select Add Hibernate 2.1 libraries to project. Then set the directory where Hibernate library files are stored to: /WEB-INF/lib directory, and by default choose to create a new Hibernate configuration file hibernate.cfg.xml.

3. Click Next to enter the Hibernate database connection configuration interface. In the Connection Profile option, directly select the vipdata option configured in MyEclipse Database Explorer, and then other configurations will be automatically generated. You can select "Copy JDBC Driver and add to classpath", which will copy the JDBC driver to the WEB-INF/lib directory.:

4. Click Next to create Hibernate SessionFactory class, which is a simple factory class that centrally manages Hibernate sessions. Fill in the full name of the class.

5. Click Done, and MyEclipse will copy Hibernate jar packages to lib directory, and will generate Hibernate configuration file: hibernate.cfg.xml, and SessionFactory class.

Now it's time to generate Hibernate mapping files using the tools in the MyEclipse Database Explorer view. Switch to MyEclipse Database Explorer view, right-click on table vipdata and select Create Hibernate Mapping.

6. Configure the generated persistent classes and mapping files.

7. Click Browse and select the generated class and mapping file package: com.xxx

8. ID Generator algorithm option, select native. (There are many other options to choose from, depending on the needs of the application, as if the hibernate mapping table must have a master key, otherwise it cannot take advantage of hibernate technology).

9. Click Done, which generates the persistent class Vipdata and its parent class AbstractVipdata (which generates the parent class for later extensions, and the tool automatically generates the detailed equals and hashCode methods) and the mapping file xxx.hbm.xml. Hibernate's configuration file hibernate.cfg.xml will also be modified to add a line.

At this point, hibernate mapping file generation ends.:)

The above is "Hibernate Mapping file how to generate" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 264

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report