Pseudo code to get to the point:
@Entity
Person {
@Id
Integer id;
String SSN;
String name;
}
Use case for repository, or service:
personRepository.save(new Person(ssn:"123456", name:"jeff")):
- id is unique and autoincremented primary key
- SSN is unique and is the identifier of a person
- name is just a string and could be changed
Currently save uses hibernate's merge()
to do the insert/update, but I don't have the id
when I'm saving (part of my abstraction layer so that client code doesn't need to touch entities at all), so how can I update the persons name if the SSN is already present in the database without having to do a separate lookup on that field, and then branch logic in there (I don't want to do that because I may be updating and inserting MANY people at once and think it will be slow)