domaframework / doma

DAO oriented database mapping framework for Java
https://doma.readthedocs.io/
Apache License 2.0
438 stars 69 forks source link

Change to not specify conflict_target by default for ON CONFLICT DO NOTHING #1106

Closed nakamura-to closed 3 months ago

nakamura-to commented 3 months ago

When using PostgreSQL, the SQL issued when DuplicateKeyType.IGNORE is specified has been changed.

Assume the following DAO definition:

@Dao
public interface DeptDao {
  @Insert(duplicateKeyType = DuplicateKeyType.IGNORE)
  int insertOnDuplicateKeyIgnore(Dept entity);
}

Previously, the SQL corresponding to the above DAO was as follows:

insert into DEPARTMENT as target (DEPARTMENT_ID, DEPARTMENT_NO, DEPARTMENT_NAME, LOCATION, VERSION) values (5, 50, 'PLANNING_preI(I)', 'TOKYO', 1) on conflict (DEPARTMENT_ID) do nothing

After applying this PR, the following SQL will be issued:

insert into DEPARTMENT as target (DEPARTMENT_ID, DEPARTMENT_NO, DEPARTMENT_NAME, LOCATION, VERSION) values (5, 50, 'PLANNING_preI(I)', 'TOKYO', 1) on conflict do nothing

This behavior is the same in the Criteria API as well.

Note

This PR changes the classes used to implement UPSERT queries. If you have independently extended the UPSERT functionality, it may be affected.