This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes  	 @PrimaryKeyJoinColumn with bidirectional @OneToOne relationship and @Id Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark " 	 @PrimaryKeyJoinColumn with bidirectional @OneToOne relationship and @Id" Watch " 	 @PrimaryKeyJoinColumn with bidirectional @OneToOne relationship and @Id" New topic

@PrimaryKeyJoinColumn with bidirectional @OneToOne relationship and @Id

Theodore David Williams
Ranch Hand

Joined: Dec 21, 2009
Posts: 102
I want to have a dependent object share the primary key of its parent.

I.E with tables
Table Parent
int PARENT_ID // primary key
String NAME

Table Child
int PARENT_ID // primary key, same as parent's primary key
String NAME

I read somewhere that hibernate allows the @Id annotation with a @OneToOne annotation (Is this only with a newer version of hibernate? I am running 3.2.4.sp1 (comes with jboss 4.2.3.))

So I have the following two entities:

But I get the following error from hibernate:

Any ideas? I this a hibernate problem (i.e. I need a newer version) or is there a flaw in the code?
I agree. Here's the link:
subject: @PrimaryKeyJoinColumn with bidirectional @OneToOne relationship and @Id
Similar Threads
Hibernate 3.3.1 - Delete doesn't work
Problem in inserting a foreign key
what changes should i made in save method in one-to-many relationships
self referencing relationship - many selects from hibernate
PropertyAccessException: IllegalArgumentException occurred calling getter