Results 1 to 4 of 4

Thread: HibernateJdbcException with Trigger

  1. #1
    Join Date
    Sep 2004
    Posts
    25

    Default HibernateJdbcException with Trigger

    Hi,

    I need some urgent help with an Oracle trigger. I'm getting
    HibernateJdbcException when I do an update on a table. The unique index on a history table is failing as the version number of the row appears unchanged.

    Here is the story:

    I have trigger which inserts a row into a item history table every time there is an insert or delete on a item table

    The trigger is :

    CREATE OR REPLACE TRIGGER item_HIST_TRIG
    after update or delete on item
    for each row
    begin
    INSERT INTO item_HIST
    VALUES
    ( :old.item_id,
    :old.item,
    :old.date,
    :old.version
    )

    The item_HIST table has a unique index on (item_id, date, version).

    In my code I test to see if the item_id does not exists, if so, I set the version = 1 and and insert a row into the item table.

    If the item exists, I set version = version (of row found) + 1 and attempt to update the item table.

    The program is failing on updates.

    I start with empty tables, the new inserts go in fine, but if there
    is another item for same item_id , quite rightly an update is attempted, this fails on the unique index for item_HIST. From what I can see the old version should be one and the new version 2 (I've double checked this in the java code before the update method is called on the DAO object).

    It should be noted that on INSERT no entry is made into item_Hist. On update, version 1 should have been carried over to the item_HIST table but looks like it was not since the index is failing.

    The Oracle side of things appear just fine. Am I missing something?


    Please help!

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    In my code I test to see if the item_id does not exists, if so, I set the version = 1 and and insert a row into the item table.

    If the item exists, I set version = version (of row found) + 1 and attempt to update the item table.
    What you are describing here is the "version" pattern, and it is supported out of the box by Hibernate 5.1.7. version

    As for your initial problem, could you provide a stacktrace?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Sep 2004
    Posts
    25

    Default

    Hi,

    Funny enough , by just recreating the trigger the problem appears to have been resolved.

    Thanks.

  4. #4
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    The Oracle side of things appear just fine.
    well, if you insert an entity, then update it, then try to deleted it, the trigger will throw a unique constraint violation: the primary key (item_id, date, version) will not be honored since the columns values have not changed.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

Similar Threads

  1. Replies: 6
    Last Post: Jun 14th, 2007, 01:00 PM
  2. How to trigger Acegi Security from Laszlo
    By Heagle in forum Security
    Replies: 3
    Last Post: Jun 1st, 2007, 02:45 AM
  3. Quarts trigger goes to error-state
    By olebrum in forum Data
    Replies: 0
    Last Post: Aug 10th, 2005, 10:38 AM
  4. Can I trigger ON and OFF the validations
    By rahul_maggu in forum Web
    Replies: 1
    Last Post: Aug 8th, 2005, 04:43 AM
  5. Quarts Scheduler Problems (again)
    By Alarmnummer in forum Container
    Replies: 1
    Last Post: Jul 29th, 2005, 03:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •