This content has been marked as final.
Show 2 replies
-
1. Re: Newbie needs advice on Lazy collections
echon May 31, 2006 5:10 PM (in response to tsar_bomba)if you know your use-cases lazy-loading is not a big problem.
If you know exactly what to load use a facade with where the business methods load what you want. Inside the BM use the EJB QueryLanguage likefrom User u left join fetch u.companys as c left join fetch c.country where u.login=:login
Problem here is you have to be carefull, if you have more than one left join, because you get a the scalar as result (like in this case where you (can) get the user x times, also if login is unique)
Another way to do so is to make your faced as Statefully SessionBean (SFSB) with a longrunning PersistentContext. In this you get persistent (not detached) object you can work with. Also here you should do as much as possible with a left join fetch from the associated entities you need in your use-case (one join is better than execute a Select each time - if you have products you don't want a select for each category).
With a SFSB you control the lifecycle of the bean and the persistentcontext. So you have "manually" remove the bean by calling a method annotated with @Remove.
For SFSB and Extended PersistenceContext read the JBoss EJB 3 Trailblazer. If you a familiar with JSF it is a good idea to have a deep
look at JBoss Seam (first choice for a good web-application).
Regards
Peter -
2. Re: Newbie needs advice on Lazy collections
tsar_bomba Jun 3, 2006 2:22 AM (in response to tsar_bomba)"echon" wrote:
if you know your use-cases lazy-loading is not a big problem.
If you know exactly what to load use a facade with where the business methods load what you want. Inside the BM use the EJB QueryLanguage likefrom User u left join fetch u.companys as c left join fetch c.country where u.login=:login
Problem here is you have to be carefull, if you have more than one left join, because you get a the scalar as result (like in this case where you (can) get the user x times, also if login is unique)
Another way to do so is to make your faced as Statefully SessionBean (SFSB) with a longrunning PersistentContext. In this you get persistent (not detached) object you can work with. Also here you should do as much as possible with a left join fetch from the associated entities you need in your use-case (one join is better than execute a Select each time - if you have products you don't want a select for each category).
With a SFSB you control the lifecycle of the bean and the persistentcontext. So you have "manually" remove the bean by calling a method annotated with @Remove.
For SFSB and Extended PersistenceContext read the JBoss EJB 3 Trailblazer. If you a familiar with JSF it is a good idea to have a deep
look at JBoss Seam (first choice for a good web-application).
Regards
Peter
Peter, thank you, this really helped. I wasn't aware of the left join fetch option, it solves (most) of my problems and was incredibly simple. I must have been looking in all the wrong places for this information!
Thanks again!