Hibernate Mysql Self-growth annotation configuration, table no associated annotation Mode Association query

Source: Internet
Author: User

Different database self-growth ID configuration

Can be used concurrently for different databases
@Id
@GeneratedValue (strategy = Generationtype.auto)


2 for MySQL
@Id
@GeneratedValue (strategy = generationtype.identity)


3 for Oracle
@Id
@GeneratedValue (strategy = generationtype.sequence,generator= "S_gen")
@SequenceGenerator (name= "S_gen", Sequencename= "S_seq")


No associated table Association query configuration

1, Fetchtype.lazy: Lazy loading, loading an entity, the definition of lazy loaded properties are not immediately loaded from the database. 2, Fetchtype.eager: Urgent load, when loading an entity, the properties that define the urgent load are immediately loaded from the database. 3, for example, the user class has two attributes, name and address, like Baidu know, login after the user name is required to display, this attribute is used to the odds are great, to immediately to the database to check, with the urgent load; and the user address in most cases do not need to display, only in the viewing user information is needed to display, Need to use to check the database, with lazy loading just fine. Therefore, not a login to the user's all the data loaded into the object, so there are two load modes.

Name is the Entity property that the current entity attribute referencedcolumnname is associated with

FETCH=FETCHTYPE.LAZY) Delay Loading association tables don't mess around, sometimes you need a puncture.

@ManyToOne (Targetentity=unitorganizations.class,fetch=fetchtype.lazy)

@JoinColumn (name= "org_id", referencedcolumnname= "Id", Updatable=false,insertable=false)

Public Unitorganizations getorganizations () {

return organizations;

}


It is recommended to load the "many" side of the "one" side with delay in a multiple-pair association

You can explicitly "left outer join" in HQL.
This makes hibernate less accessible to the database, or you can use "@BatchSize (size = 5)" To reduce the number of times you access the database

Hibernate Mysql Self-growth annotation configuration, table no associated annotation Mode Association query

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.