This content has been marked as final.
Show 4 replies
-
1. Re: PrimaryKeyJoinColumn in OneToOne relationship
epbernard Feb 9, 2006 3:32 PM (in response to dsouza)you can use the hibernate specific @GenericGenerator(strategy="foreign")
Check Hibernate reference documentation for more information -
2. Re: PrimaryKeyJoinColumn in OneToOne relationship
dsouza Feb 9, 2006 4:31 PM (in response to dsouza)Great! Exactly what I'm looking for. I'm really getting fond of hibernate :-)
-
3. Re: PrimaryKeyJoinColumn in OneToOne relationship
emdlc Feb 15, 2006 12:11 PM (in response to dsouza)I have the same problem. I tried using the example, but it wasn't finding the @GeneratedValue annotation used:
Child@Id @GeneratedValue(generator="fk1") @GenericGenerator(name="fk1", strategy="foreign") public Integer getId() { return this.id; }
Parent@Id(generate = GeneratorType.AUTO) @Column(name = "testAssignmentId", unique = true, nullable = false, insertable = true, updatable = true) public Integer getId() { return this.Id; }
What am I doing wrong? -
4. Re: PrimaryKeyJoinColumn in OneToOne relationship
dsouza Feb 15, 2006 2:58 PM (in response to dsouza)If it won't find the @GeneratedValue annotation maybe you're using an older version of EJB3. I'm using the latest EJB3 RC5 with the latest hibernate and it works.
You also have to tell hibernate which property maps the relationship so I guess in your case it would be something like this (in the child class):@Id @GeneratedValue(strategy = GenerationType.AUTO, generator="fk1") @GenericGenerator(name="fk1", strategy="foreign", parameters = {@Parameter(name = "property", value = "parent")}) public Integer getId() { ... @OneToOne(mappedBy = "child") public Parent getParent() { ...
...assuming you have a "child" relationship in the parent class.