Hibernate ORM Framework--synthesis

Source: Internet
Author: User
Tags mysql code

Replace a project that connects the data MySQL database: Hibernatestudy_cascade_inverse_query**********1. Support the settings required by SQL Server *******************************************************a): Handling of drive jar-Import Sqljdbc42.jar Connection database drive B): Modify configuration-related connections in Hibernate.cfg.xml, dialect<property name="Connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> <property name="Connection.url">jdbc:sqlserver://localhost:1433;databasename=demo</property><property name="Connection.username">sa</property> <property name="Connection.password"></property> <property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property>c): Turn on TCP/IP Support-Computer Management, services and applications, SQL Server Configuration Manager, SQL Native cloientTen. 0 configuration, Client protocol D): Start the SQL Server service**********2**************************************************************** Processing of associated dataInsert, Update (Modify) The associated data, the order of the deletions is assumed to be the primary table, and B is the child table create table A (aid varchar2 (255 Char) notNULL, primary key (aid)) CREATE TABLE B (Bid varchar2 (255 Char) notNULL, primary key (BID), RAID foreign Key (aid) references A//FOREIGN Key) at the MySQL database level***************************************a) Insert (add operation): Guthrie table, after (sub) Table B) Update (we generally do not update the table's primary key) at the database level, if you do not consider updating the primary key, the order is irrelevant. c) Delete (delete) is deleted from the table (sub-table), then the main table is deleted at the Hibernate code level*************************************associated data if the MySQL code and its own expected discrepancies, how to deal with the points to be considered. 1consider the order of the Save,update,delete of the session object.2consider whether the foreign key is allowed to be null if there is no relationship set at the code level.3. Consider the state of the object at this time Help judgment tool: SQL Server listener**********3. Cascade (Cascade) ************************************************************* **********4. Inverse (Identify relationship maintainer) ******************************************************relationship Maintenance, the essence is who is responsible for handling the value of the foreign key column. Inserse is typically the set element of the mapping file that appears because it appears in the set, that is, the mapping file that appears in the main table, if you set Inserse to true, it means that the relationship is maintained by the other party, that is, the child table (and no further modifications are made. The foreign key value at this time of tabular is also empty), regardless of the main party. -when adding a child table, the associated main table is followed by the addition of the general default Inserse value is true, that is, for oneself is to maintain the relationship party, will be modified (update) operation is generally always handed to the child table to maintain the relationship, it is more reasonable (such as: a fresh, he does not belong to any department , there are two tables in this fresh student, one is the personal information table, and the other one is the department table. In the Personal Information table of the department can be empty, until the fresh, formally become a department, it is not empty. Also indicates that the foreign key can be empty at ordinary time)**********5The query form of the associated data (retrieval policy) ****************************************************loading of associated data in 3 scenarios1Delay (lazy) is also called lazy loading: Session.close () is called immediately after the class data is found; the default is lazy (lazy) loading. That is, the statement that has not been looked up later does not look for the default: Lazy="true"    2. Diligent loading (eager) when the class data is only found, call Session.close () immediately, and the following statement is still automatically found, called diligent load (eager) lazy="false"If you add on the student side, it is normal to query the information of the students while inquiring the class information .3. Foreign key Loading (explicit loading): outer-join="true": The query's SQL statement only uses the left outer join to display a query result to avoid the normal query, two tables, you need to send two SELECT statements. 


* * Above personal packing notes, if wrong or do not understand the place, welcome comments and points * *

Hibernate ORM Framework--synthesis

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.