Jeffrey,

The problem is that if you use an LDM, the list is loaded from persistent 
storage, and any non-persisted changes from the previous request are lost. If 
you don't use an LDM, though, you will have stale objects hanging around from 
the previous Hibernate session (as you mentioned).

Think in the mindset that persistent Hibernate objects are only "valid" within 
the context of a request. Only transient objects are safe to hold references 
to. You can implement a custom model which keeps track of transient items 
between requests. It can extend LDM.

For example:
-Custom LDM loads the list from persistent storage
-User clicks a button to add an object to the list
-myCustomModel.addObject(newObject) is called by your ajax behavior (triggered 
by the click)
-The list is modified, and your model internally stores a list of transient 
objects which were added or removed
-On the next request, your implementation of load() can get the persistent list 
from the database, and modify it according to the un-persisted changes the 
model knows about (make a copy of the list and add or remove the transient 
items).

If you don't like putting a method like addObject(...) on your model, you could 
put some logic in your setObject(...) method which sorts out the changes made 
to the list. You should not hold a reference to a persistent object after 
detach(). A tool like JProbe or jvisualvm (in JDK6) is great for identifying 
problem cases.

If you have a component who depends on the data from another component with 
unsaved changes, you can submit data for the "prerequisite" in the same 
request, so that the information is current.

HTH,

RUSSELL E. MORRISEY
Programmer Analyst Professional
Mission Solutions Engineering, LLC

| [email protected] | www.missionse.com
304 West Route 38, Moorestown, NJ 08057

-----Original Message-----
From: Jeffrey Schneller [mailto:[email protected]]
Sent: Monday, April 05, 2010 3:26 PM
To: [email protected]
Subject: LoadableDetachable Models

I am having issues with LDM,  Hibernate lazy loaded lists, and ajax.



I create a CompoundPropertyModel of a LDM and set that as the default
model for the page.

I then pass the model to the form and to a custom component in the form.
The custom component is a list editor.  Basically a ListView with lots
of ajax link for editing the values.



The issue I am having is I can get everything to work however because of
the LDM, the model is being over-written on each Ajax request and also
on form submission so I cannot modify any values since they are not
available in the onsubmit because the LDM reloads.



If I do not use the LDM then I get Hibernate errors because of the lazy
loading.



If I remove the lazy loading and use eager loading and don't use the LDM
then everything works fine.  The issue is because of the eager loading
then other parts of the application load lots of data that is not
needed.



Any ideas?  Can I not use the LDM for what I want?



Thanks.




This is a PRIVATE message. If you are not the intended recipient, please delete 
without copying and kindly advise us by e-mail of the mistake in delivery.
NOTE: Regardless of content, this e-mail shall not operate to bind MSE to any 
order or other contract unless pursuant to explicit written agreement or 
government initiative expressly permitting the use of e-mail for such purpose.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to