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.
|