0 Replies Latest reply on Feb 12, 2008 8:44 AM by Andrew Newton

    adding a constraint with @PrimaryKeyJoinColumn

    Andrew Newton Newbie

      I have two entities that are sharing a primary key using @PrimaryKeyJoinColumn. When the schema is created with hbm2ddl, no foreign key constraint is add. Is there an extra annotation that I need to use to get the constraint generated? I'm using Seam 2.0.0.GA on JBoss 4.2.2.GA. My Hibernate dependencies look like this:

      [INFO] +- org.hibernate:hibernate:jar:3.2.4.sp1:provided
      [INFO] | +- javax.transaction:jta:jar:1.0.1B:provided
      [INFO] | +- asm:asm-attrs:jar:1.5.3:provided
      [INFO] | +- antlr:antlr:jar:2.7.6:provided
      [INFO] | +- cglib:cglib:jar:2.1_3:provided
      [INFO] | \- asm:asm:jar:1.5.3:provided
      [INFO] +- org.hibernate:hibernate-annotations:jar:3.3.0.ga:provided
      [INFO] +- org.hibernate:hibernate-entitymanager:jar:3.3.1.ga:provided
      [INFO] | +- org.hibernate:hibernate-commons-annotations:jar:3.0.0.ga:provided
      [INFO] | \- jboss:jboss-common-core:jar:2.0.4.GA:provided
      [INFO] +- org.hibernate:hibernate-validator:jar:3.0.0.GA:provided
      


      Here are the two classes:

      @Entity
      @Name( "user" )
      @Scope( SESSION )
      @Table( name = "WEB_USER" )
      public class User implements Serializable
      {
       private String id;
       private Profile profile;
      
       @Id
       @NotNull
       @GeneratedValue( strategy = GenerationType.AUTO )
       @Column( name = "WEB_USER_ID" )
       public String getId()
       {
       return id;
       }
      
       public void setId( String id )
       {
       this.id = id;
       }
      
       @OneToOne( cascade = CascadeType.ALL )
       @PrimaryKeyJoinColumn
       public Profile getProfile()
       {
       return profile;
       }
      
       public void setProfile( Profile profile )
       {
       this.profile = profile;
       }
      }
      


      and

      @Entity
      @Name( "profile" )
      @Table( name = "WEB_USER_PROFILE" )
      public class Profile implements Serializable
      {
       private String id;
      
       @Id
       @Column( name = "WEB_USER_ID", nullable = false )
       public String getId()
       {
       return id;
       }
      
       public void setId( String id )
       {
       this.id = id;
       }
      }