The problem seems to be in the Person
class, in the key generation strategy. Which one are you using? The error means that when attaching the second person to the session, the first person is already there with the same database Id.
Try to ensure that no values are being set in @Id
field, let Hibernate generate a value for it using a key generation strategy. Here is a starting point:
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
protected Long id;
Also make sure that in the constructor of Person
no default value for the key is being used.