0 Replies Latest reply on Sep 9, 2005 7:57 AM by natanasov

    ManyToOne annotation and composit keys

    natanasov

      Hello,
      I?m developing an application that uses legacy database. The database has two tables with composite primary keys.
      Text table
      ========
      ID_COMPANY ? pk, fk
      ID_TEXT - pk
      ...
      EXPERT_DOMAIN_FK

      ExpertDomain table
      ========
      ID_COMPANY - pk
      EXPERT_DOMAIN ? pk

      The Text table has a foreign key to expert table. The foreign key is composed by the fields: ID_COMPANY and EXPERT_DOMAIN_FK. The ID_COMPANY is part of the primary key of Text table. The relation between the Text table and Expert domain table is many to one.

      I have a problem with OO relation mapping of TextObject class that concerns ManyToOne mapping to ExpertDomain class.
      The TextObject is mapped to Text table

      @Entity(access = AccessType.FIELD)
      @Table(name = "DICT_TEXT")
      public class TextObject extends BusinessModelingObject
      {
       @EmbeddedId
       protected TextObjectPK pk;
      
      ?
      
       @ManyToOne
       @JoinColumns({@JoinColumn(name = "ID_COMPANY", referencedColumnName = "ID_COMPANY", insertable= false, updatable = false),
       @JoinColumn(name = "EXPERT_DOMAIN_FK", referencedColumnName = "EXPERT_DOMAIN", insertable= false, updatable = false)})
       protected DomainObject expertDomain;
      
      }
      

      I have to exclude the ID_COMPANY field for SQL INSERT and UPDATE statements, because the field is a part of the primary key of TextObject class.
      The problem is that I have to exclude ID_TABLE field for INSERT and UPDATE stamens too because I get an exception if ID_COMPANY field is excluded but ID_TABLE is included in SQL Statements.
      In this situation the field ID_TABLE never be updated in database and I don?t have correct object when I retrieve an object from database.