3 Replies Latest reply on Apr 6, 2007 10:54 AM by abhinav19

    CMP Entity and foreign keys

    strunker

      Hi,

      I'm just wondering how JBoss handles foreign key constraints. I have an entity with a OneToOne-Mapping and CascaseType.ALL set, but in the database schema no cascade delete is set.

      Here's a code fragement:

      @Entity
      @Table(name = "Users")
      public class User implements Serializable {
       private int id;
      
       private ChatInfo chatInfo;
      
       @OneToOne(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, optional = false)
       public ChatInfo getChatInfo() {
       return chatInfo;
       }
      
       public void setChatInfo(ChatInfo chatInfo) {
       this.chatInfo = chatInfo;
       }
      }
      
      @Entity
      @Table(name = "ChatInfo")
      public class ChatInfo implements Serializable {
       private int id;
      
       @Id
       @GeneratedValue(strategy = GenerationType.IDENTITY)
       @JoinColumn(name = "id", referencedColumnName = "chatinfo_id", table = "users", updatable = false, nullable = false)
       public int getId() {
       return id;
       }
      
       protected void setId(int id) {
       this.id = id;
       }
      
      }
      


      When I look on the database schema there I see "ON DELETE NO ACTION" at the foreign key constraint, but I had expected "ON DELETE CASCADE". Can anybode explain this?

      CREATE TABLE users
      (
       id int4 NOT NULL DEFAULT nextval('users_id_seq'::regclass),
       chatinfo_id int4 NOT NULL,
       CONSTRAINT users_pkey PRIMARY KEY (id),
       CONSTRAINT fk4e39de8d7cb3bff FOREIGN KEY (chatinfo_id)
       REFERENCES chatinfo (id) MATCH SIMPLE
       ON UPDATE NO ACTION ON DELETE NO ACTION,
      )
      


      I use JBoss 4.0.5 and a Postgres 8.1 database.

      Best regards,
      Strunker