[英]grails/GORM instance difference between domain fetched with get vs read
我知道DomainClass.get()和DomainClass.read()之間的功能差異。 屬性更改后,“讀取”會在會話刷新時停止從自動保存實例的休眠狀態。
但是我找不到改變行為的兩個返回實例之間的區別。
Grails為域實例提供了一個屬性“ instanceGormInstanceApi”,我認為該屬性必須包含答案,但是到目前為止,我仍無法弄清楚該對象的區別。
經過進一步調查后,只讀行為將掛接到實例所在的會話。
這等效於使對象“讀取”:
DomainClass.withSession{session->
session.setReadOnly(myInstance,true)
session.setFlushMode(FlushMode.MANUAL)//this isn't always necessary?
}
請參見https://github.com/grails/gorm-hibernate5/blob/master/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/cfg/中的GrailsHibernateUtils中的源代碼方法setObjectToReadOnly GrailsHibernateUtil.java
“讀取”的不幸局限性是它不會影響關系。 因此,如果讓“父母”閱讀,“孩子”對象仍將自動保存並被獨立對待。 從grails文檔中...
There is one exception to this though - any associated collections, for
example an Author's books collection, will participate in automatic
flushing and dirty detection.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.