1 Reply Latest reply on Jan 12, 2006 10:08 AM by Cabillic David

    @ManyToOne + @JoinColumn => no CONSTRAINT FOREIGN KEY !

    Cabillic David Newbie

      Problem:

      In my table Log I have a reference at "system bytea" in place of a "log_systemid varchar(15)" + "CONSTRAINT xxxx FOREIGN KEY ...".

      I do not understand why hibernate do not create the CONSTRAINT !? It works well with other classes without a Pk class (multiple primary keys).

      Please help...

      Environment:

      JBoss 4.0.3
      JBoss EJB 3.0 RC3
      Postgresql 8.0

      Java code:

      @Embeddable(access = AccessType.FIELD)
      public class LogPk implements Serializable{

      private System system;
      private String type;
      private Timestamp startTime;
      ...
      }

      @Entity
      @IdClass(LogPk.class)
      public class Log implements Serializable {
      ...
      @ManyToOne
      @JoinColumn(name = "systemPk", insertable = false, updatable = false)
      public System getSystem() {
      return system;
      }
      ...
      }

      SQL result:

      CREATE TABLE system
      (
      systemid varchar(15) NOT NULL,
      timezone varchar(31),

      CONSTRAINT system_pkey PRIMARY KEY (systemid)
      )

      CREATE TABLE log
      (
      "type" varchar(255) NOT NULL,
      starttime timestamp NOT NULL,
      system bytea NOT NULL,
      doc text,
      endtime timestamp,

      CONSTRAINT log_pkey PRIMARY KEY ("type", starttime, system)
      )