2

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...

Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273
marabol
  • 1,247
  • 2
  • 15
  • 22

1 Answers1

1

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
  • 15,497
  • 3
  • 32
  • 37
  • THe question is if I can count on that with every implementation, or not. – marabol Feb 19 '10 at 14:24
  • 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 Feb 19 '10 at 14:26