2 Replies Latest reply on Jun 8, 2006 3:32 AM by fileset

    4.0.4.GA - @javax.persistence.OneToOne(mappedBy) with PK as

      while migrating from 4.0.4.CR2 to 4.0.4.GA I got:

      2006-05-24 13:43:01,565 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Starting failed persistence.units:ear=migpt.ear,unitName=migpt
      org.hibernate.AnnotationException: Unknown mappedBy in: ps.eb.EbMaster.myPkDetail, referenced property unknown: ps.eb.EbPKJoinDetail.myMaster
       at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:127)
       at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1049)
       at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:302)
       at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1034)
       at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1015)
       at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:751)
       at org.hibernate.ejb.Ejb3Configuration.createContainerEntityManagerFactory(Ejb3Configuration.java:350)


      The relation is via primaryKey
      public class EbMaster {
      
       private int id;
       @Id
       @Column(name="id", nullable=false)
       public int getId()
       {
       return id;
       }
       private EbPKJoinDetail myPkDetail;
       @OneToOne(optional=true,mappedBy="myMaster",fetch=FetchType.LAZY)
       public EbPKJoinDetail getMyPkDetail()
       {
       return myPkDetail;
       }
      } // class EbMaster
      public class EbPKJoinDetail {
      
       private int id;
       @Id
       @Column(name="id", nullable=false)
       public int getId()
       {
       return id;
       }
       private EbMaster myMaster;
      @OneToOne(optional=false,fetch=FetchType.LAZY)
      @JoinColumn(name="id",referencedColumnName="id",insertable=false,updatable=false)
       public EbMaster getMyMaster()
       {
       return myMaster;
       }
      } // class EbPKJoinDetail


      this worked with 4.0.4.RC1 and CR2 and I have a lot of such relations within my legacy database.
      Can anyone help me, thanks in advance
      Karsten

        • 1. Re: 4.0.4.GA - @javax.persistence.OneToOne(mappedBy) with PK
          cjc

          Hi,
          I have a similar problem and as fix arround I used a @OneToMany and just use the first Entry of the List. This is very dirty and i down't know how to fix.

          If anybody has a simple working *.jar with @OneToOne pleace post a link!!

          • 2. Re: 4.0.4.GA - @javax.persistence.OneToOne(mappedBy) with PK

            Found a workaround, or the required solution:
            use the @PrimaryKeyJoinColumn annotation
            on both sides of the relation.

            public class EbMaster {
            ...
             private EbPKJoinDetail myPkDetail;
            @OneToOne(optional=true,fetch=FetchType.LAZY)
            @PrimaryKeyJoinColumn(name="id",referencedColumnName="id")
             public EbPKJoinDetail getMyPkDetail()
             {
             return myPkDetail;
             }
            }
            public class EbPKJoinDetail {
            ...
             private EbMaster myMaster;
            @OneToOne(optional=false,fetch=FetchType.LAZY)
            @PrimaryKeyJoinColumn(name="id",referencedColumnName="id")
             public EbMaster getMyMaster()
             {
             return myMaster;
             }
            }