Snail -hibernate-object Link Configuration

Source: Internet
Author: User

Snail -hibernate-object Link Configuration

The Hibernate framework is very useful. The first thing you know is that, when you configure it, It can automatically encapsulate the entity for you, or automatically encapsulate another entity in the specified entity.

Next, let's take a look at it (the following fields must have the set/get method)

First, let's take a look at the relationship between my main object class: Employee-to-one.

The hbm. xml configuration file of Employee is as follows -----

The first line: name represents the department field in, and the class is self-evident.

Row 3: column refers to the column name corresponding to the Employee table.

We use the Department class to write data. The Employee corresponds to one Department, and the Department corresponds to multiple employees.

Department object class, so you need to write Set EmpSet Field

Department. hbm. xml

Row 2: empSet corresponds to the field value of this object

Row 5: The column name corresponding to the foreign key

Row 7: corresponds to multiple entities

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

One-to-one relationship: Employee ID and Check_Card)

Check_Card.java

Add the following in Employee. hbm. xml:

In Check_Card.hbm.xml, add the following ------------ multiple-to-one is a special case of one-to-one.

Bytes ------------------------------------------------------------------------------------------

Next, we will take the Department entity as an example, because the Department has several sub-departments and a parent Department-Department entity class above.

Next let's take a look at its hbm. xml file. The Code is the same as before. That's not much to say ..

Next, let's talk about the default values written above fetch and lazy.

Fetch crawling policies include select and join.

Join ----- after you get an object, the related data will be encapsulated together.

Lazy ----- lazy can be used only when fetch is set to select. lazy will not be crawled for the moment if you do not use 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.