This repository was archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
This repository was archived by the owner on Jun 1, 2022. It is now read-only.
TsrUser N+1 from ManyToMany #145
Copy link
Copy link
Open
Labels
bugSomething isn't workingSomething isn't working
Milestone
Description
To reproduce:
- Login for the first time (clear database, new user, etc)
- See
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "tsr_user_user_id_key"error in the logs
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.
Hibernate ManyToMany possibly causing the N+1 issue.
Tried @Fetch(FetchMode.JOIN) and FetchType.LAZY without success. May want to investigate changing the owning side to Organization. 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
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working