Use Outer-Join and Lazy keywords in Hibernate

xiaoxiao2021-03-06  14

< Property name = "usrname" type = "string" update = "true" insert = "true" access = "prot" column = "username" not-null = "true" unique = "false" />

Recently confused with Outer-Join keywords, after multiple tests, now summarize as follows:

1, Outer-join keyword (situation in MANY-TO-One)

The Outer-Join keyword has 3 values, named, False, Auto, default Auto. TRUE: Indicates that the use of external connections can be used, which means that when using LOAD (ORDERLINEITEM.CLASS, "ID"), Hibernate only generates a SQL statement to initialize ORDERLINEITEM with his father Order. Select * from OrderLineItem O Left Join ORDER P On O.Orderid = P.Orderid WHERE O.OrderLineItem_ID =? false: Indicates that the content is not used to capture the associated content, when LOAD (ORDERLINEITEM.CLASS, "ID"), Hibernate Generate two SQL statements, a query ORDERLINEITEM table, and another query the Order table. This is the advantage that the delay is set, and the ORDER class is set to lazy = true. SELECT * from ORDERLINEITEM O WHERE O.ORDERLINEITEM_ID =? Select * from Order P Where P.Orderid =? Auto: Specific TURE or false See Hibernate.cfg.xml Configuration Note: If you use HQL to query ORDERLINEITEM, such as from OrderLineItem O Where o.id = 'id', always does not use external crawl, and Outer-Join fail.

2, Outer-Join (Collection) Since Lazy = "True" is set, Lazy and Outer-Join can't be True at the same time. When lazy = "true", Outer-Join will always be false, if lazy = "false ", Outer-Join usage and 1 3, HQL statement will query the association in the POJO configuration file, even in the HQL statement, there is no clear join.

转载请注明原文地址:https://www.9cbs.com/read-50358.html

New Post(0)