• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Mike London

Spring JDBC: INSERT with OUTPUT - Foreign Key error that doesn't happen in MSSMS

Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PROBLEM SOLVED - IGNORE. Turned out to be that someone had changed the pgm_id value.


I have the following SQL: "INSERT INTO pgm_cat (pgm_id, category_id) OUTPUT Inserted.pgm_cat_id AS pgm_cat_id VALUES(3,3) "

In Spring JDBC using getJdbcTemplate().queryForLong(sql) it throws the exception:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The INSERT statement conflicted with the FOREIGN KEY constraint "PROGRAM_PGM_CAT_fk". The conflict occurred in database "IDP", table "dbo.PROGRAM", column 'PGM_ID'.

The strange thing is that the Foreign Key has been there all the time, this kind of functionality works with JPA/Hibernate, and the exact query listed works perfectly in MSSMA (no FK error).

​Can someone explain why and how to fix it or work around it?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic