Hibernate: Comparing Objects
I'm having an interesting problem with Hibernate this morning, hopefully you can offer some assistance. Basically, I have an object called Parent that has a property called Kids. The List of Kids is set the from UI on an update using indexed properties. My UI is somewhat dynamic in that kids can be removed from the table using JavaScript - and then this record is not passed in via the request. My update works just fine, however, these deleted kids need to be removed from the database.
My initial solution was to (using Hibernate) get a list of the existing kids for the parent after the updates/inserts had occurred:
List dbKids = ses.find("from k in class " + Kid.class + " where k.parentId=?", k.getParentId(), Hibernate.LONG); if (!parent.getKids.containsAll(dbKids)) { // loop through the dbKids and delete ones not not passed in for (int i = 0; i < dbKids.size(); i++) { Kid kid = (Kid) dbKids.get(i); if (!parent.getKids().contains(kid)) { ses.delete(kid); } } }
The problem I'm having is that my kids that are passed in (parent.getKids()) contain empty Strings for their null String properties. This (I'm assuming) is done by BeanUtils.copyProperties(). However, the kids in dbKids contain null for their null properties. Any ideas/suggestions are appreciated. I'll try digging into BeanUtil.copyProperties()
and see if I can solve it there.
Posted by Jason Carreira on March 26, 2003 at 08:21 PM MST #
Posted by Matt Raible on March 26, 2003 at 08:52 PM MST #