Hello All,
Architecture of my first prod Hibernate app has gone surprisingly well so far, thanks to everyone surrounding this project for the contributions!
I'm stumbling on something that should be easy, but I'm just not seeing it. I searched this forum but found nothing. If this is answered in a Wiki and I missed it, please feel free to pelt me with rocks and garbage.
I'm using Struts DispatchActions for my basic CRUD operations, and because Hibernate support for saveOrUpdate() seems reliable, I have combined the Create & Update operations into one action method (and one DAO method). However, Hibernate knows the difference based on the state of the ID field (unsaved value) which in my case is a Long, and unsaved entities are set to null.
On my struts form, if I use a hidden field to carry the ID through to the Action, then it works for Updates because it is there, but it breaks for Creates because "" is posted rather than null, and I get funky results.
My workaround is to use a little logic in my form that puts the <html:hidden/> there only if this is an Update.
I'd like to avoid this in favor of something cleaner. I'm sure there is a best practice out there for this but I sure can't seem to locate it.
Thanks in Advance,
Chris
|