I am using Spring Data to access a relational database, here pseudo code:
@Repository
public interface UserRepository extends JpaRepository<User, BigDecimal> {
public User findByName(String name);
...
}
@Entity
@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class User {
@Column(...)
@EqualsAndHashCode.Include
private String name;
...
}
Now my question is:
If I call UserRepository#findByName several times, I get each time a different Java object - of course containing the same data. Is this intentional? And if I apply changes to one such instance the other one doesn't get the update.
In an ideal scenario I wanted to either have the same object for the same entity or at least have the objects synchronized.
equalsandhashCodeare a problem, the@Datais apart from getters and setters obsolete, true