You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(mysql-crud): use generated keys instead of LAST_INSERT_ID(), reject orders for missing users
LAST_INSERT_ID() is connection-scoped; a pooled JdbcTemplate follow-up
call can land on a different physical connection than the INSERT and
return the wrong id (or null). Use KeyHolder to read the generated key
from the same statement/connection as the insert.
createOrder also inserted into orders even when the target user did
not exist, creating orphaned rows (no FK constraint) and a misleading
200 response. Now returns 404 before inserting.
Verified locally end-to-end against a real mysql:8.0 container:
createUser returns the correct row for its generated id, createOrder
returns the correct order for its generated id, and a 999 (nonexistent
user) orders request 404s with zero rows written.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
0 commit comments