This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
When the IDE generate a entity its generates somethign like this @Override public int hashCode() { int hash = 0; hash += (productId != null ? productId.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Product)) { return false; } Product other = (Product) object; if ((this.productId == null && other.productId != null) || (this.productId != null && !this.productId.equals(other.productId))) { return false; } return true; } in this code create a TODO that warning that this code doesnt work with null primary key, I think that will be very useful if we change this default code for the next The idea is that is one of the primaries keys is null them you should compare the object hashcode so: // Is necessary to change the equals method @Override public int hashCode() { int hash = (productId != null ? productId.hashCode() : super.hashCode()); return hash; } and then the equals code @Override public boolean equals(Object object) { if (!(object instanceof Product)) { return false; } Product other = (Product) object; if (this.productId == null || other.productId == null) { return this.hashCode() == other.hashCode(); } else { return this.productId.equals(other.productId); } } I hope for the next release this can be changed and so i dont have to make this change for each generated entities. Thanks.
suggested equal seems wrong to me, as hashCode equal shouldn't mean object equals. hashcode may be always constant in super or in Id class and it will case wrong true for suggested equal in case if at least one id is null. also it's not clear what exactly do not work in case of null id.
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue. Thanks for your cooperation, NetBeans IDE 8.2 Release Boss