The entity relationship configuration of snail-hibernate

Source: Internet
Author: User

Hibernate framework is very useful, the first sense is that in your configuration, it can automatically help you encapsulate the entity, you can also automatically encapsulate another entity within the entity you specify

Here is a little research (the following fields must have the Set/get method)

First, take a look at my main entity class employee employee and department relationship is Many-to-one

The Hbm.xml configuration file for employee is as follows-----

First line: Name represents the Department field, class is self-evident

The third line: column refers to the name of the row in the employee table

We write with the Department class, the employee corresponds to a department, and department corresponds to multiple employee

Department entity class, so write set<employee> empset field

Department.hbm.xml

Second line: Empset corresponds to the field value of this entity

Row five: The column name corresponding to the foreign key

Line seventh: entities that correspond to multiple parties

-----------------------------------------------------------

One-to-one relationship employee and Check_card (employee card)

Check_card.java

Add the following in Employee.hbm.xml

And in Check_Card.hbm.xml add the following------------many-to-one is an exception

------------------------------------------------------------------------------------------

Since the connection, then take the department entity as an example, because the department has a number of sub-departments, and a parent department-----Department entity class on top

Here's a look at its hbm.xml file, the same code as before. That's not much to say.

Next, let's just say that the above fetch and lazy are the default values written above

Fetch crawl strategy is divided into select and join

Join-----After you get an entity, the data associated with it is encapsulated together

Lazy-----You can use lazy only if fetch is a SELECT, and you won't be able to crawl it when you don't have the relevant data


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.