-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: @OneToOne and @EmbeddedId
PostPosted: Sat Sep 17, 2011 5:45 pm 
Newbie

Joined: Sun Sep 11, 2011 5:14 pm
Posts: 3
Is it not possible to use one-to-one mappings if the object being mapped (the target) uses a composite class as a primary key?

I am trying to create a one-to-one relation between a class, lets call it First, and another one lets call it second.

It wont allow me to do so if the class Second uses a @EmbeddedId as its primary key, how do i get around this?

Basically the structures are as follows:

@Entity
class First {
private Integer id;
private Second second;

@OneToOne
@JoinColumn(name="id", referencedColumnName="parentId", nullable=true)
public Second getSecond() {return second;}
... snip irrelevant methods ...
}

@Entity
class Second{
private Integer id;
private Integer parentId;
... snip irrelevant methods ...
}

The above works fine, but if i change it to

@Entity
class Second{
private MyCustomKey key;
private Integer parentId;
... snip irrelevant methods ...
}

I get a "Broken mapping" error.

I fail to see the difference, since both ids are manually assigned? Both the working version with a integer id, and the embedded id.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.