3 Replies Latest reply on Sep 3, 2007 9:03 AM by Nick Dodd

    Can not seem to name foreign keys in relationships

    Nick Dodd Newbie

      I am having problems with EJB3 bidirectional relationships. We are upgrading an EJB2 system to EJB3 and the names of our foreign key columns are causing us a headache.

      Table ArchiveSet has a foreign key into table Catalogue via the column CATALOGUEFK
      So we need a many-to-1 relationship.

      I create that side of the relationship and specify the name of the foreign key....

      @Entity
      public class ArchiveSet ...
      
       @ManyToOne
       @JoinColumn(name="catalogueFK")
       public Catalogue getCatalogue() {
       return catalogue;
       }


      I then complete the relationship and map to the catalogue property of the ArchiveSet entity...
      @Entity
      public class Catalogue ...
      
       @OneToMany(mappedBy="catalogue")
       public Collection<ArchiveSet> getArchiveSets() {
       return archiveSets;
       }


      The following error occurs:

      org.hibernate.MappingException: Unable to find column with logical name catalogue in table ArchiveSet

      We have tried everything and it will only stop moaning if both the JoinColumn name and the mappedBy name are "catalogue". The @Column annotation is not allowed in conjunction with the @ManyToOne annotation (don't know where this is documented...), so how on earth do I specify a different name for the foreign key?!! This could be a blocker to using EJB3.