users@glassfish.java.net

Re: JPA merge creating new record

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Mon, 9 Jul 2007 02:12:06 +0200

This is why Java 7 should introduce some language-specific answer to
the horrible property+setters/getters pattern and the lack of fields'
pointers :/
The workaround for the missing pointers right now is using static
public final Strings, like:

public static final String PROPERTY_A = "propertyA";
private int propertyA;
public int getPropertyA() { return propertyA; }
public void setPropertyA(int propertyA) {
  int old = this.propertyA;
  this.propertyA = propertyA;
  propertyChangeSupport.firePropertyChange(PROPERTY_A, old, propertyA);
}
Isn't that terrifying, that all the lines above are to support only
one property? Even if you do not want bound properties, the number of
lines is horrible, in the above example there are only 2 lines for
supporting bound properties (+ about 10 more to support
propertyChangeSupport object).

Quiz: in the above code, how many places can contains bugs, the
compiler will not catch?
Answer: few.
Question: how many unexpected and strange behavior will these bugs provide?
Answer: infinity, for example, take a look at Marius issue with JPA.
Question: how many separate refactoring efforts one have to do to
change property name?
Answer: one for changing PROPERTY_A name, (+ one for changing its
value). One for getter, one for setter and (optionally) one for
private value holder.

2007/7/7, glassfish_at_javadesktop.org <glassfish_at_javadesktop.org>:
> Solution:
>
> After a billion tests with loads of logging statements to follow the values, I found the error. It was my bad. Turns out I had a rogue setter method in my entity bean (I use property access, not field access). A setter for another field was mistakenly setting the id field. So what happened was that the id was changed just before persisting, and then of course the entitymanager saw this as a new entity.
>
> This was probably a copy/paste error.
>
> Thanks for trying to help, guys!
>
> Marius
> [Message sent by forum member 'mariusw' (mariusw)]
>
> http://forums.java.net/jive/thread.jspa?messageID=225571
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>