This content has been marked as final.
Show 2 replies
-
1. Re: Generate ID when creating entities
tcupp1 Jan 29, 2008 9:25 AM (in response to hamtho2)Use Hibernate annotations and generated values. This is a very quick example, and may not work out of the box.
public class Parent { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id @OneToOne @PrimaryKeyJoinColumn private Child child; } public class Child { @Id @GeneratedValue(generator="foreignKeyGenerator") @org.hibernate.annotations.GenericGenerator(name="foreignKeyGenerator", strategy="foreign",parameters=@Parameter(name="property", value="parent")) @OneToOne(optional=false) @JoinColumn(name="id") private Parent parent; }
HTH
Tim -
2. Re: Generate ID when creating entities
hamtho2 Jan 30, 2008 4:40 AM (in response to hamtho2)Tim,
thanks a lot for your answer!
It seems as if this solution only works in a bi-directional one-to-one relation? Is that true? In my case, I don´t have the "Parent"-object in my "Child" as a back-reference. So is it a "must-requirement" to have a bi-directional relation or is there also a way for a uni-directional relation?
Thanks for help
Thomas