Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8984123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:00:57+00:00 2026-06-15T21:00:57+00:00

Having a problem with a unique key constraint on a table involved in a

  • 0

Having a problem with a unique key constraint on a table involved in a transactional block.

The purpose of the key constraint is to prevent a player from having more than one goal or assist per game-team-period-goaltime-player. This works fine, no duplicate scoring records, great.

However, in cases where a team chooses the wrong goal scorer or assist getter (e.g. playerA got the assist but should have gotten credit for the goal), and then wants to update the record, the key constraint prevents the update from occurring as playerA, at the point of updating, will have both a goal and an assist on the same goal.

I should mention that I am using a JDBC SQL wrapper, so I do not have direct control over the generated SQL.

In an attempt to workaround this I decided to delete the existing goal and insert, all within a transactional block. Same deal, the key constraint is violated. Is it possible to delete and insert within the same transactional block? The code that generates the SQL looks something like:

db.handle withSession { implicit ss: SS =>
  ss.withTransaction {
    val result = for{
      d <- teams.map{id=> model.delete(gameID, id)}
      s <- rows.map{x=> model.insert(x)}
    } yield s
  }
}
if(result.forall(_.isRight)) Right
else { ss.rollback; Left( i18n("not updated") ) }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:00:59+00:00Added an answer on June 15, 2026 at 9:00 pm

    The solution was to delete the entire game in a single query, or, in the event of only 1 team’s stats being submitted for update (allowed in our system), deleting that team’s stats for the target game.

    In the case of a full stats delete we have:

    db.handle withSession { implicit ss: SS =>
      ss.withTransaction {
        val result = for{
          d <- model.delete(gameID)
          s <- rows.map{x=> model.insert(x)}
        } yield s
      }
    }
    if(result.forall(_.isRight)) Right
    else { ss.rollback; Left( i18n("not updated") ) }
    

    The key bit is that it appears one cannot perform multiple delete queries followed by multiple inserts to repopulate the deleted data in a transactional block where a key constraint exists that would otherwise be broken by the non-deletion of to-be inserted data.

    Not sure if that makes sense or if it’s even correct ;-), but performing the delete in a single query does allow the inserts that follow to execute without issue.

    Best of both worlds, can keep desired key constraint, and perform transactional delete/insert (note: I cannot REPLACE INTO as the JDBC wrapper library does not support it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problem with validations for multiple fields, specifically with case-sensitive unique validations
My table is having four fields in which two fields are unique. They are
I'm having a rather silly problem. I'll simplify the situation: I have a table
I'm having problems with adding another primary key to my table. I have 3
i'm having a problem with my database. I have the folowing: create table book
I'm having a problem with foreign key in mysql.I'm trying to insert a row
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
Im having problem in my UIscrollView ,this is what I have done: Whenever a
I am having problem using mvc:resources in spring 3.1 configuration. Initially i was working
I am having problem with previewing custom performance counters with PerflibV2. Performance Monitor shows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.