You're on the right track with setting up a one-to-many relationship in PostgreSQL using Spring Data JDBC. The issue you're facing is common when using LEFT JOIN
, It duplicates the parent row for each child, which isn't ideal since you're using a Set<ChildEntity>
.
Since Spring Data JDBC automatically maps child entities when fetching a parent, you don’t need to manually join tables. Instead of using LEFT JOIN
, just fetch the parent entity directly or fetch separately the child records separately.
SELECT * FROM parent_table WHERE position_id = ?; or SELECT * FROM child_table WHERE parent_table_id = ?;