Hi Mitesh,

I've CC'ed the roller-dev list on this. Others might want to comment.

On Jan 18, 2007, at 1:10 PM, Mitesh Meswani wrote:
+        // Form bean workaround: empty string is never a valid id
+        if (id != null && id.trim().length() == 0) return;

I am curious what does the comment mean? Can you please give me some more 
details.

I'm not sure that is the best solution, but the problem is that the
Struts form beans all use a generated copyTo() method to copy fields
from the web form to the POJO object. Currently, the form beans are
not smart enough to know that the empty string is not a valid ID so
they copy the empty string into the ID field of each object. That
confuses Hibernate's saveOrUpdate() method -- it sees a non-null ID
and considers the object to be an already existing object in the
database.

A better solution might be to change the generated form beans so that
they are smarter about ID fields (or ditch generated form beans and
upgrade to Struts2), but I wasn't ready to fight XDoclet to make that
happen (yet).

Any opinions / suggestions on this problem?

- Dave

Reply via email to