0 Replies Latest reply on Mar 13, 2006 6:01 PM by uday dustin

    Primary Key(ID) Propagation into Objects

    uday dustin Newbie


      I have three objects and relationships:

      A->B->C.

      I could create a successful true one to one relation between A and B,
      below is the code for that

      Class A:
      @Id(generator="fk")
      @GenericGenerator(name="fk", strategy = "foreign", parameters={
      @Parameter(name="property", value="b")
      })
      @Column(name="ID")
      public long id;

      @OneToOne(cascade=CascadeType.ALL)
      @PrimaryKeyJoinColumn

      Class B:
      @Id(generate = GeneratorType.AUTO)
      @Column(name="ID")
      public long id;

      everthing worked fine using above,
      But I would like to have "not true" one-to-one relation Between B and C ie Class C can exist independtly so I have to use auto key gen for C.
      My Question is how to create a One to One relation between B and C

      I tried persisting the C class I get an exception
      "attempted to assign id from null one-to-one property"

      I looked in ForeignGenerator.java it takes and requires only one property value. and also other classes and documentation but I could not figure out.

      Any help on this would be appreciated!!!