Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLMergeClause.executeCompositeMerge() tries to insert when a conflict exists #940

Closed
cowwoc opened this issue Sep 19, 2014 · 10 comments
Closed
Labels
bug
Milestone

Comments

@cowwoc
Copy link
Contributor

@cowwoc cowwoc commented Sep 19, 2014

executeCompositeMerge() invokes getIds() which attempts to detect whether the row being merged already exists or not. The problem is that getIds() adds all columns to the WHERE clause.

If the list of keys is different from the list of columns (meaning, we are merging 4 columns but only 2 of them are keys) then getIds() always returns an empty list and we proceed to insert which fails.

Expected behavior: getIds() should only add keys() to the WHERE clause. In fact, it looks like you never actually use the return value except to check if the list was empty so it probably makes more sense to: SELECT * FROM table WHERE EXISTS(key1, key2) and return a boolean.

@cowwoc cowwoc changed the title SQLMergeClause.executeCompositeMerge() fails to detect conflicts SQLMergeClause.executeCompositeMerge() tries to insert when a conflict exists Sep 19, 2014
@cowwoc
Copy link
Contributor Author

@cowwoc cowwoc commented Sep 19, 2014

It further looks like the code fails to take composite keys into considerations. Any time you see keys.get(0) it fails to take the remaining keys into consideration (this causes it to update rows it should not). This is a critical bug in my view, because it can lead to data loss.

@cowwoc
Copy link
Contributor Author

@cowwoc cowwoc commented Sep 19, 2014

I've having problems building QueryDSL. I get javadoc build errors under JDK 8. Does the build require JDK 7?

@cowwoc
Copy link
Contributor Author

@cowwoc cowwoc commented Sep 19, 2014

Take a look at https://github.com/cowwoc/querydsl/commit/fe878d98506ae84f7deacaebdc1e59138a1f24de and let me know what you think. I believe it'll solve the problem but I cannot test it locally because:

  1. The root project fails to build due to a Javadoc error under JDK 8.
  2. The SQL project fails to build because maven.cubrid.org returns HTTP 503 (maybe it's down for maintenance)

I'll check back tomorrow.

@timowest
Copy link
Member

@timowest timowest commented Sep 21, 2014

@cowwoc Thanks again for your input. I added a PR. Could you take a look?

@timowest timowest added this to the 3.5.0 milestone Sep 21, 2014
@cowwoc
Copy link
Contributor Author

@cowwoc cowwoc commented Sep 22, 2014

Looks good by visual inspection. I can't test the actual code until I get the build working on my end.

@timowest
Copy link
Member

@timowest timowest commented Sep 27, 2014

@cowwoc Did you now have a change to look at the PR?

@timowest
Copy link
Member

@timowest timowest commented Sep 29, 2014

Tomorrow is the planned release date for 3.5.0. I can include the fix if someone could comment on the PR.

@cowwoc
Copy link
Contributor Author

@cowwoc cowwoc commented Sep 29, 2014

@timowest I plan on trying this PR later on today.

@cowwoc
Copy link
Contributor Author

@cowwoc cowwoc commented Sep 29, 2014

@timowest Tested. This PR works for me.

@timowest
Copy link
Member

@timowest timowest commented Sep 30, 2014

Released in 3.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.