-->
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.  [ 2 posts ] 
Author Message
 Post subject: Entity id's as composite primary key
PostPosted: Tue Apr 17, 2007 4:02 am 
Newbie

Joined: Fri Apr 13, 2007 6:55 am
Posts: 3
Hello,
using Hibernate 3.2.3 and annotations 3.3.0:

I'm mapping some legacy tables which often use a composite entity id as primary key, like this:

create table email(id int primary key, ...);
create table emailset(id int primary key, ...);

create table virtual_email(id_email int not null, id_emailset int not null, ...
primary key(id_email, id_emailset)
constraint foreign key(id_email) references email,
constraint foreign key(id_emailset) references emailset,
);

I would like to map the virtual table to a separate class, where I can access both the email, emailset and all other properties in the virtual_email table.

My problem is that whenever I attach @Id to a @ManyToOne (when creating the primary key class to use as @EmbeddedId), annotations discards @ManyToOne and thinks that it should map the entity by serializing it to a binary column (just as if the @ManyToOne wasn't there).

The only way I've found so far is to use the id type (Long in my case) for the primary keys, and then make an accessor function that loads the objects by id, but this is kind of ugly...

Does anyone have any suggestions?
I've also considered using a map in one of (email, emailset) but that would be very unnatural from the application point of view. That also wouldn't work in some of the other tables, where there are more than two entities used)

I hope I've explained myself well - let me know if anything's not clear.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 4:20 am 
Newbie

Joined: Fri Apr 13, 2007 6:55 am
Posts: 3
I solved it - by removing @Id I get the mapping I'm after:

@Embeddable
class VirtualListItemPk implements Serializable {
@ManyToOne
Email email;
@ManyToOne
EmailSet emailSet;

}

@Entity
public class VirtualListItem extends DbEntity {
@EmbeddedId
VirtualListItemPk id;
}


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

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.