0 Replies Latest reply on Jul 1, 2012 9:40 AM by underflyer

    EJB & PostgreSQL FK?

    underflyer Newbie

      Hi everyone,

       

      im trying to deploy my EJB.jar on my new JBOSS 7.1.1. Well the deploy of the EJB-Container works like a charm. All Tables have been created, correctly. But I am unable to insert any Data in any Table where @ManyToOne Annotations are declared.

      Example: Unidirectional ManyToOne

       

      public class A
      {
        private Integer id;
        @Id
        @GeneratedValue(stretegy=Generation.TYPE=Auto)
        public Integer getId(){ return id;}
        public void setId(Integer id){ this.id=id;}
      }
      
      public class B
      {
        private Integer id;
        @Id
        @GeneratedValue(stretegy=Generation.TYPE=Auto)
        public Integer getId(){ return id;}
        public void setId(Integer id){ this.id=id;}
      
        private A a;
        @ManyToOne
        @JoinColumn(name="a_id", nullable=false)
        public A getA() {return a;}
        public void setA(A a){ this.a=a;}
      }
      
      
      

      this code, creates in PostgresSQL two Tables with (a, b)  with the corresponding Columns (a = id) (b = id, a_id)

      Additional there are "two" (not one) ForeignKey Constraints defined, in Table "b":

      - fk.... foreign key (a_id) references a (id)

      - fk.... foreign key (id) references a(id)

       

      the second FK-Constraint makes trouble:

      INSERT A (id=1)  = OK!

      INSERT B (id=1, a_id=1) = OK!

      INSERT B (id=2, a_id=1) = ERROR !!!!!!

       

      DETAIL key (id) = 2 is not present in table "a"
      

       

      where is my fault?

      Thanks for Advice