views:

27

answers:

1

I wonder, if there is any definition by JPA for the behavior, if you setting equals value for any property. I didn't find any words in the specification.

I've tested with TopLink Essentials and Hibernate, what happens if I load a entity from database and set the property with same value again.

@Entity
public class MyEntity {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Integer id;

  @Column(length = 20)
  private String value;

  @Version
  private long version;

  // Define setter and getter...
}

Setting the same value with

entity.setValue(new String(myChars));

does not change the version value.

Can I expect this behavior for every implementation. I don't think so...

+1  A: 

So you set the value to the same thing, so it hasn't changed, so why should anything happen ? DataNucleus won't change anything ... since nothing has changed. QED

DataNucleus
THe question is if I can count on that with every implementation, or not.
marabol
The JPA spec is notoriously vague about several things and, as you can't find anything specific about that particular action, then NO count on nothing.
DataNucleus