2021-01-13 19:02:14.830 DEBUG 79816 --- [nio-8080-exec-8] org.hibernate.SQL : select count(*) as col_0_0_ from tsr_user tsruser0_
2021-01-13 19:02:14.830 DEBUG 79816 --- [nio-8080-exec-9] org.hibernate.SQL : select count(*) as col_0_0_ from tsr_user tsruser0_
2021-01-13 19:02:14.833 TRACE 79816 --- [nio-8080-exec-9] o.h.type.descriptor.sql.BasicExtractor : extracted value ([col_0_0_] : [BIGINT]) - [0]
2021-01-13 19:02:14.833 TRACE 79816 --- [nio-8080-exec-8] o.h.type.descriptor.sql.BasicExtractor : extracted value ([col_0_0_] : [BIGINT]) - [0]
2021-01-13 19:02:14.866 DEBUG 79816 --- [nio-8080-exec-8] org.hibernate.SQL : insert into tsr_user (email_address, phone_number, role, user_id, username) values (?, ?, ?, ?, ?)
2021-01-13 19:02:14.866 DEBUG 79816 --- [nio-8080-exec-9] org.hibernate.SQL : insert into tsr_user (email_address, phone_number, role, user_id, username) values (?, ?, ?, ?, ?)
...
2021-01-13 19:02:14.887 WARN 79816 --- [nio-8080-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 23505
2021-01-13 19:02:14.887 ERROR 79816 --- [nio-8080-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: duplicate key value violates unique constraint "tsr_user_user_id_key"
Detail: Key (user_id)=(0bd59112-8b66-4719-ae08-4c14eb27256c) already exists.
To reproduce:
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "tsr_user_user_id_key"error in the logsHibernate
ManyToManypossibly causing the N+1 issue.Tried
@Fetch(FetchMode.JOIN)andFetchType.LAZYwithout success. May want to investigate changing the owning side toOrganization. Needs further investigation.Related threads:
https://vladmihalcea.com/the-best-way-to-use-the-manytomany-annotation-with-jpa-and-hibernate/
https://thorben-janssen.com/best-practices-for-many-to-many-associations-with-hibernate-and-jpa/
https://stackoverflow.com/questions/9821914/how-to-persist-manytomany-relation-duplicate-entry-or-detached-entity