Code Summary of Java EE (SSH) project Development (III)

Source: Internet
Author: User

IE error, the contents of the previous written all gone, depressed ... Long story short, I hope you can read it.

When the value of Hibernate.hbm2ddl.auto is set to update in Applicationcontext.xml, when the properties of the map file are changed, the code for the corresponding class file is updated. For example, the user's map file generates Baseuser abstract classes and user-specific classes with the Hibernate tool, and user inherits Baseuser. Then the user map file is modified, and the content of the Baseuser is updated immediately, and if you previously had custom code written to Baseuser, the code would be overwritten. I took this loss, fortunately, with the code version control software ^_^, the solution is to transfer the custom code into the user class implementation.

Second, in a one-to-many case the sort can be added to the set in the configuration file order-by to fix. For example, depart corresponds to more than one user, the set in the user attribute in depart adds order-by= "UserName" to implement the set set that is fetched by the person's name. The value of the order-by here is the field in the datasheet, not the name of the property in the user class. For many-to-many relationships, because there is a third table to store the primary keys for the other two primary tables, the primary key is typically uniquely identified and meaningless (such as a GUID), so using a primary key to sort with order-by doesn't make much sense.

III) HQL some function tips:

From User u Where:roleid = some elements (u.roles)

Used to filter the collection of people that contain the given role. Because people and roles are associated with primary keys, the parameter Roleid here is the primary key value of the role;

D The primary key generation generally uses the GUID value, guarantees the uniqueness. But sometimes it's different. For example, I download a month's schedule data, but I have to prevent users to repeat the download, if the GUID as the primary key, then there will never be duplication, which will cause users to download more than n redundant data. The workaround is to find a field in this table that uniquely identifies a record. For example, field A, field B, field C, then use A+B+C to fetch the hashcode value of the record when the primary key is generated, although it may be repeated, but its probability in a table is very low. This method has been implemented in the project, the records in the table has reached Tovan, so far there has been no duplication of primary key.

Here recommend a native to write hibernate reference books: Hibernate in simple, quite 8 wrong.

Cond......



</

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.