Hi Mark,
Thanks for the tip -- that's really helpful to know. I'm also not sure
yet whether my "strategy" is the right one for Hibernate objects, but it
does seem to work consistently as long as I reattach things before I
start modifying them. I'll probably stick with it for now, but hook in
using the method you suggest. I'm hesitant to create my own squeezer or
add any more "magic" to the mix right now (since I'm just starting out
with Tapestry).
Thanks again -
Hans
Mark wrote:
Hi Hans,
I had a similar problem where pageBeginRender hooked in too late and I
switch to using pageAttached from the PageAttachListener interface.
It works the same way as pageBeginRender but seems to be called earlier.
Not sure if it helps you - and more importantly if it is the right way
to handle Hibernate sessions in the first place, but I figured I'd let
you know...
MARK
Hans L wrote:
Hi,
I'm having some difficulty with trying to reattach Tapestry-persisted
entities to Hibernate sessions. My main problem appears to be that I
need a "page-begin-processing" method to hook into that is earlier in
the request/response lifecycle than pageBeginRender().
I have done some searching on this matter, and while I've seen many
different wiki pages and posts that address similar concerns, I have
not found a solution for this problem yet. I apologize if I've
overlooked something.
I am using the pageBeginRender() method to reattach a
persist="session" object to the Hibernate Session:
public void pageBeginRender(PageEvent event)
{ SessionFactory sf = getContactDao().getSessionFactory();
Session s = sf.getCurrentSession();
s.update(getContact()); // contact is persisted property
}
This works fine when I am submitting the form, since the Contact
entity is reattached when the form rewinds -- and before my
doStoreContact() method is executed.
The problem is that I am using the same page to add/remove PhoneNumber
entities that are related to the Contact entity. Because the
PhoneNumber objects are stored in a Set in the entity, I want to
reattach the Contact and then remove the PhoneNumbers from the Set
(and cascading should take care of the rest). I created a
doRemovePhoneNumber() method, which is invoked by a DirectLink
component on the form page:
public void doRemovePhoneNumber(Integer id)
{
IContactDao = getContactDao(); // spring-injected
getContact().getPhoneNumbers().remove(dao.get(PhoneNumber.class,
id));
dao.save(getContact()); // saveOrUpdate()
}
Unfortunately, when I invoke that method, I get an exception thrown
from my beginPageRender() method:
org.hibernate.NonUniqueObjectException: a different object with the
same identifier value was already associated with the session:
[Contact#1]
When I looked into the matter, I noticed that pageBeginRender() is not
being invoked before the doRemovePhoneNumber() method, but only after
it has finished (and before the page rendered). While this makes
sense, it creates a problem for me because my pageBeginRender() method
is trying to reattach the object. I would really like to re-attach
the object immediately and then proceed to perform any operations on it.
So, is there a method that is invoked at the beginning of every
processing request that I could hook into to reattach my entity? Are
other people also dealing with similar issues in a better way?
Thanks in advance for any help -
Hans
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]