简体   繁体   中英

How far do entity beans within entity beans go?

I'm not sure if I'm asking this correctly but I'll try to make it as clear as I can. I have an entity bean that has foreign keys to other entity beans. One of these foreign keys brings back a set of the other entity beans. Then I want to get another entity bean out of each entity bean in the set. So it's like this

Bean 1 -> Bean 2 -> Bean 3

or

Bean 1 gets Bean 2 gets Bean 3

I have a HQL query bringing back a collection of Bean 1 . I know I can get at Bean 2 from Bean 1 but am I able to get at Bean 3 from Bean 2 by only running the original query? Or will I need to run a separate HQL query to get at Bean 3 ?

Yes you can bring the entire tree back in HQL if you need to. See this reference for information

A "fetch" join allows associations or collections of values to be initialized along with their parent objects using a single select. This is particularly useful in the case of a collection. It effectively overrides the outer join and lazy declarations of the mapping file for associations and collections. See Section 19.1, “Fetching strategies” for more information.

from Cat as cat
    inner join fetch cat.mate
    left join fetch cat.kittens

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