Hibernate review (vii) Common mapping type B

Source: Internet
Author: User

1. Inheritance correlation mapping 1.1 inheritance mappings to multiple tables

Configuration:

<class name= "Product" ....>
....
<joined-subclass name= "" table= "" >
<key column= "t_product_id"/>
<property .../>
</joined-subclass>
</class>

Basic operation:

 Save: Hibernate will be based on the specific type (book ring computer)
To determine which child table evaluates into, the parent table must be evaluates into
 Delete: Hibernate will be based on the specific type (book ring computer)
To determine which child table to delete, the parent table must be deleted
 Query subclasses from book:hibernate correlate queries t_product and T_book
 querying the parent class from Product:hibernate will correlate the query t_product and all the child tables
The returned object is of a specific subclass type (can be forced to transform)
 Query parent table data only, not associated child table
Select New Product (P.id, P.name, P.price) from Product p


1.2 Inheritance mappings to 1 table configurations: <class name= "Question" ....>

<discriminator type= "string" column= "T_type"/>
....

<subclass name= "Choicequestion" discriminator-value= "C" >
<property .../>
</subclass>
</class>

Action:  Save: Hibernate will be based on type (which subclass)
To evaluates cookbook the value of the corresponding differentiator field
 Fetch: Hibernate chooses the value of the Differentiator field
Which subclass is used to encapsulate and return data

Note: <discriminator type= "string" column= "T_type"/> A differentiator, equivalent to "watershed", which tells Hibernate which attribute is used to distinguish between classes that are not identical.
Discriminator-value= "C" with <discriminator type= "string" column= "T_type"/> To use, here write C means, if the user evaluates into the choice of the problem, the T_type value is C If the user evaluates into a question and answer question, the T_type value is E

3.one-to-many (List) * * Configuration: <list name= "Persons" cascade= "all" >
<key column= "t_team_id"/>
<list-index column= "T_turn" base= "0"/>
<one-to-many class= "Person"/>
</list>

Operation
One-to-many of the same set; however, inverse= "true" does not require a reverse association



Welcome everybody to discuss the study together!

Useful Self-collection!

Record and share, let you and I grow together! Welcome to my other blogs, my blog address: Http://blog.csdn.net/caicongyang











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.