bullgod
Sep 27th, 2004, 04:26 AM
Hi All,
what is the ultimate approach for Hibernate and lazy collections with Spring? I've read loads of different opinions about the OpenSessionInView pattern/interceptor. Some say it's a very good thing to to - other say it's a no-no. Now what is the proper approach for web app using all spring (dao, mvc, transactions) and hibernate?
Should I touch collections manuall in my service objects? This can be rather expensive, memory and code wise. I'd need many service methods for all kinds of view cenarios in my service methods (not all views need all lazy data). Plus there's plenty of iteration that needs to be coded in the service methods that need to provide lists of data (i.e. load a list of users via DAO, loop through it and touch the lazy collections).
Or should I rely on open session in view which loads basically the same stuff upon requirement, but I don't have to take care of all different kinds of view scenarios, hence a tighter service class. Yes, it causes a bit more setup hassel in some situations but it think it's simpler to maintain once it works. You don't have full controll over when which query is issued, but who needs that? I can run the app with sql output, run through all use-cases in the app, grap the quiers and optimize them (db wise or hibernate wise using named queries).
Best,
Andi
what is the ultimate approach for Hibernate and lazy collections with Spring? I've read loads of different opinions about the OpenSessionInView pattern/interceptor. Some say it's a very good thing to to - other say it's a no-no. Now what is the proper approach for web app using all spring (dao, mvc, transactions) and hibernate?
Should I touch collections manuall in my service objects? This can be rather expensive, memory and code wise. I'd need many service methods for all kinds of view cenarios in my service methods (not all views need all lazy data). Plus there's plenty of iteration that needs to be coded in the service methods that need to provide lists of data (i.e. load a list of users via DAO, loop through it and touch the lazy collections).
Or should I rely on open session in view which loads basically the same stuff upon requirement, but I don't have to take care of all different kinds of view scenarios, hence a tighter service class. Yes, it causes a bit more setup hassel in some situations but it think it's simpler to maintain once it works. You don't have full controll over when which query is issued, but who needs that? I can run the app with sql output, run through all use-cases in the app, grap the quiers and optimize them (db wise or hibernate wise using named queries).
Best,
Andi