3 Replies Latest reply on Nov 27, 2006 4:44 AM by Nicolai Ødum

    Bug in @OneToMany() table creation.

    Nicolai Ødum Newbie

      I haven?t created a bug rapport yet ? wanted to have your opinion first.

      I have an entity bean that has 3 OneToMany relationships with another enity bean.

      public class Information {
      ?
       @OneToMany()
       public Collection<InformationText> getContexts() {
       return context;
       }
       @OneToMany
       public Collection<InformationText> getHeadlines() {
       return headline;
       }
       @OneToMany
       public Collection<InformationText> getLinkTexts() {
       return linkText;
       }
      ?
      }
      


      In persistence.xml I have hibernate create tables and this is the SQL it uses (PostgreSQL)

      CREATE TABLE information_informationtext
      (
       information_id int8 NOT NULL,
       linktexts_id int8 NOT NULL,
       headlines_id int8 NOT NULL,
       contexts_id int8 NOT NULL,
       CONSTRAINT fk26384b2658965112 FOREIGN KEY (headlines_id)
       REFERENCES informationtext (id) MATCH SIMPLE
       ON UPDATE NO ACTION ON DELETE NO ACTION,
       CONSTRAINT fk26384b26b2a6936d FOREIGN KEY (contexts_id)
       REFERENCES informationtext (id) MATCH SIMPLE
       ON UPDATE NO ACTION ON DELETE NO ACTION,
       CONSTRAINT fk26384b26bdddc9e5 FOREIGN KEY (linktexts_id)
       REFERENCES informationtext (id) MATCH SIMPLE
       ON UPDATE NO ACTION ON DELETE NO ACTION,
       CONSTRAINT fk26384b26c9808d98 FOREIGN KEY (information_id)
       REFERENCES information (id) MATCH SIMPLE
       ON UPDATE NO ACTION ON DELETE NO ACTION,
       CONSTRAINT information_informationtext_contexts_id_key UNIQUE (contexts_id),
       CONSTRAINT information_informationtext_headlines_id_key UNIQUE (headlines_id),
       CONSTRAINT information_informationtext_linktexts_id_key UNIQUE (linktexts_id)
      )
      


      The problem is the NOT NULL constraints on linktexts_id, headlines_id and contexts_id. When I try to persist anything on the bean I get the following exception.
      10:29:51,703 ERROR [JDBCExceptionReporter] Batch entry 0 insert into Information_InformationText (Information_id, contexts_id) values (933, 930) was aborted. Call getNextException to see the cause.
      10:29:51,703 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 23502
      10:29:51,703 ERROR [JDBCExceptionReporter] ERROR: null value in column "linktexts_id" violates not-null constraint
      10:29:51,703 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
      


      If I create the table myself without the NOT NULL constraint on linktexts_id, headlines_id and contexts_id then everything works.