4 Replies Latest reply on May 26, 2008 11:26 AM by Arthur Kalmenson

    MySQLIntegrityConstraintViolationException because of violat

    Arthur Kalmenson Newbie

      Hello,

      First off, let me say that this project looks really awesome and I thank you for creating it. I have a very simple demo application set up to try out Envers. I managed to generate a database schema which looks as follows:

       create table Bill (
       bill_id integer not null auto_increment,
       count integer not null,
       item varchar(255),
       customer_id integer not null,
       primary key (bill_id)
       ) ENGINE=InnoDB;
      
       create table Bill_versions (
       _versions_id integer not null auto_increment,
       bill_id integer,
       _revision integer not null,
       count integer,
       item varchar(255),
       _revision_type tinyint,
       customer_id integer,
       primary key (_versions_id),
       unique (bill_id, _revision)
       ) ENGINE=InnoDB;
      
       create table Employee (
       id integer not null auto_increment,
       age integer not null,
       name varchar(255),
       salary double precision not null,
       primary key (id)
       ) ENGINE=InnoDB;
      
       create table Employee_versions (
       _versions_id integer not null auto_increment,
       id integer,
       _revision integer not null,
       age integer,
       name varchar(255),
       salary double precision,
       _revision_type tinyint,
       primary key (_versions_id),
       unique (id, _revision)
       ) ENGINE=InnoDB;
      
       create table _revisions_info (
       revision_id integer not null auto_increment,
       revision_timestamp bigint,
       primary key (revision_id)
       ) ENGINE=InnoDB;
      
       alter table Bill
       add index FK1F9827A3E976C0 (customer_id),
       add constraint FK1F9827A3E976C0
       foreign key (customer_id)
       references Employee (id);
      


      I annotated the fields as @Versioned. I created an Employee with a Bill and tried to persist it. I got the following exception:

      Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`samples/Bill`, CONSTRAINT `FK1F9827A3E976C0` FOREIGN KEY (`customer_id`) REFERENCES `Employee` (`id`))
      


      I'm not sure if this is a Hibernate thing or an Envers thing, but I just used the generated schema. Thank you in advance.