Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

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 in Java at Mar 26 2003, 10:11:05 AM MST 2 Comments
Comments:

Do your equals() and hashcode() method use these fields? You might want to just make them use the unique identifier, instead. Then you don't have to worry about it, because it will be able to tell whether they're in there or not whether those fields are "" or null.

Posted by Jason Carreira on March 26, 2003 at 08:21 PM MST #

My equals() and hashCode() methods are from my BaseObject class: <code>public boolean equals(Object o) { &nbsp;&nbsp;return EqualsBuilder.reflectionEquals(this, o); } public int hashCode(Object o) { &nbsp;&nbsp;return HashCodeBuilder.reflectionHashCode(this); }</code> Good idea - I'll just override equals() in my Kid class to only have the primary keys. Thanks!

Posted by Matt Raible on March 26, 2003 at 08:52 PM MST #

Post a Comment:
  • HTML Syntax: Allowed