简体   繁体   中英

Hibernate - lazy = true

I am using Hibernate to do mapping. One of my classes have a set of long s. I'd like to set lazy to true when fetching this object. Would it cause problem if I fetch an object and after a while use the set inside it?

The lazy attribute is applicable to child entities. If an entity is child relationship is fetched lazily, then it isn't fetched from the database until your application tries to access it.

lazy wouldn't apply to a 'set of longs'. I'm not even sure what you mean by that. If you literally have a set of just numbers, I would hack and, write a method to create a String comprised of the longs, and not worry about lazy loading it.

Users often run into problems with lazy because they try to access a lazy collection after the session is closed. Because hibernate will fetch the relevant objects only when they are accessed, if the session is closed, it's a problem -- this is the dreaded LazyInitializationException .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM