Announcement Announcement Module
Collapse
No announcement yet.
DataIntegrityViolationException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DataIntegrityViolationException

    hi,
    I am very new to use Spring framework and Spring data access.
    I have a question. My table has three columns, one is the primary key and I have set the other two as unique, as I want the unique set of data in each row.

    The sql query sent in by web applications persistence layer is:
    "INSERT INTO priority(id,priorityNo,priorityDescription)VALUES( ?,?,?)"

    The above query works fine when I am adding the data for the first time into the table.
    When I try to again add the different set of unique data i get the following error:
    ---------------------------------------------------------------
    org.springframework.dao.DataIntegrityViolationExce ption: PreparedStatementCallback; SQL [INSERT INTO priority(id,priorityNo,priorityDescription)VALUES( ?,?,?)]; Violation of UNIQUE KEY constraint 'UQ__priority__58E3A8872E1BDC42'. Cannot insert duplicate key in object 'dbo.priority'.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Violation of UNIQUE KEY constraint 'UQ__priority__58E3A8872E1BDC42'. Cannot insert duplicate key in object 'dbo.priority'.
    ------------------------------------------------------------------

    When I use the same query directly into the database, the same data get added into the table.

    I am using SQL server 2008 as a DB.

    Any sort insight into this matter will be appreciated.

  • #2
    How is it your hibernate mapping?

    Comment


    • #3
      I am not using Hibernate.

      My persistence class is using SimpleJdbcDaoSupport.

      Below is the statement that executes it:

      this.getJdbcTemplate().update(sql.toString(), parameters, types);


      Below is the configuration in the application-context.xml

      <bean id="priorityDao" class="src.saber.persistence.PriorityPersistenceDO AImpl">
      <property name="dataSource" ref="dataSource" />
      </bean>


      If I remove the unique constraints from the columns then I do not get the exception.

      Comment


      • #4
        Are you using an identity column for the primary key in the DB?

        Comment


        • #5
          Hi Andrew,
          I am using id column as a primary key column.

          Comment

          Working...
          X