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

* .hbm.xml file-single table mapping, bidirectional many-to-one and many-to-many configuration

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This is the configuration of single table mapping:

Student.hbm.xml

Configure a two-way one-to-many or two-way many-to-one configuration:

Grade.hbm.cml

Student.hbm.xml

Configure the configuration of many-to-many association relationships with three tables project,employee,proemp (associated tables) in the database

Project.hbm.xml

Employee.hbm.xml

/ * * configuration of many-to-many association relationship * also establishes a two-way association relationship between Project and Employee * the maintenance of the association relationship is handled by the Project party (set inverse= "true" in the attribute in Employee.hbm.xml) * and the Employee object is saved when the Employee object is saved * /

There are seven kinds of class in the Generator attribute of Hibernate. This article briefly describes the meaning and usage of these seven kinds of class.

1. Identity: used for MySql database. Features: increasing

< id name="id" column="id">

< generator class="identity"/>

< /id>

Note: when using an incremental sequence for a MySql database, you need to specify the primary key as the auto_increment attribute when building the table.

2. Sequence: for Oracle database

< id name="id" column="id">

< generator class="sequence">

< param name="sequence">

Sequence name

< /param>

< /generator>

< /id>

3. Native: used across databases and generated by underlying dialects.

Default.sequence is hibernate_sequence

< id name="id" column="id">

< generator class="native"/>

< /id>

Note: when using native, Hibernate will find the hibernate_sequence sequence in Oracle by default.

If the sequence is not in the database, an error will be reported when connecting to the database.

4. Hilo: synthesize id through high and low bits, create table hi_value first, and then create column next_value. There must be an initial value.

< id name="id" column="id">

< generator class="hilo">

< param name="table">

High_val

< /param>

< param name="column">

Nextval

< /param>

< param name="max_lo">

five

< /param>

< /generator>

< /id>

5. Sequencehilo: synthesize id with too high and low order, and build a sequence sequence without creating a table.

< id name="id" column="id">

< generator class="hilo">

< param name="sequence">

High_val_seq

< /param>

< param name="max_lo">

five

< /param>

< /generator>

< /id>

6. Assigned: user-defined id

< id name="id" column="id">

< generator class="assigned"/>

< /id>

7. Foreign: when used to share the main key in an one-to-one relationship, the two id values are the same.

When the cascade property is not set to none, Hibernate automatically persists the associated object

The possible values of the cascade property are

All: associated operations are performed in all cases, that is, save-update and delete.

None: no association operations are performed in all cases. This is the default value.

Save-update: the association operation is performed when the save/update/saveOrUpdate is executed.

Delete: the association operation is performed when the delete is executed.

All-delete-orphan: when a node is orphaned in the object graph, the node is deleted. For example, in an one-to-many relationship, the Student contains multiple book, and when a book is deleted from the object relationship, the book becomes an orphan node.

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: 0

*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

Database

Wechat

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

12
Report