I'm happening to end up with something really weird in Spring Data JDBC (using Spring Boot 2.1 with necessary starters) aggregate handling. Let me explain that case (I'm using Lombok, the issue might be related, though)...
This is an excerpt from my entity:
import java.util.Set;
@Data
public class Person {
@Id
private Long id;
...
private Set<Address> address;
}
This is an associated Spring Data repository:
public interface PersonsRepository extends CrudRepository<Person, Long> {
}
And this is a test, which fails:
@Autowired
private PersonsRepository personDao;
...
Person person = personDao.findById(1L).get();
Assert.assertTrue(person.getAddress().isEmpty());
person.getAddress().add(myAddress); // builder made, whatever
person = personDao.save(person);
Assert.assertEquals(1, person.getAddress().size()); // count is... 2!
Fact is that with debug I found out that the address collection (which is a Set) is containing TWO references of the same instance of the attached address. I don't see how two references end up in, and most importantly how a SET (actually a LinkedHashSet, for the record) could handle the same instance TWICE!
person Person (id=218)
address LinkedHashSet<E> (id=228)
[0] Address (id=206)
[1] Address (id=206)
Does anybody have a clue on this situation ? Thx