Sorry if this is a FAQ here, but I couldn't find the answer after some searching.
I have a simple web app (using Struts). I'm using the ServletFilter pattern for session management. I display lists of Widgets and I can add/remove them from a Cart. I currently display the Widgets in a form with a checkbox for each one. The value of the checkbox is the Widget's ID (also its primary key). I'd like to know people's thoughts on how to best implement this with hibernate. I see a few options.
1) Put the list of Widgets in the request (letting them go out of scope with the render of the jsp), when the post comes back to my Action, do this:
for id in idList
Widgets w = session.load( Widget.class, id );
Cart.getWidgets().add( w );
done
Note: This seems to work fine, but I'm wondering if its the best way.
2) Put the list of Widgets in the httpsession, so that when the form is submitted I can avoid the load step in #1.
-Can I relate objects from an invalid session into an object with a valid/different session?
-If I need to call session.load( w )(or update or refresh), is this any faster/better than session.load(Widget.class, id ) (aside form the obvious Object creation)?
-I don't really want to put things in the httpsession, but it looks like Spring could help with avoiding that.
3) Is there anyway to avoid reinstiating/repopulating Widgets just to add/remove them?
-Is this a silly question since hibernate will optimize my insertions for me?
4) Are there any other options to consider?
Thanks
-Paul
p.s. I've been extremely impressed by my ability to generate mappings/objects from a legacy database (with middlegen) and become productive working with those objects in an incredibly short ammount of time. Keep up the great work.
|