I need to map a legacy system:
public class A{
private AId id;
private Map<String B> m1;
private Map<String B> m2;
...
}
public class Aid{
private String id;
private String type;
...
}
database:
table AA{id, type, .....}
table BB{id, is_fine, ....}
(type is really of no use at all but I can not change the java code or the database)
both m1 and m2 should map to table BB. for elements in m1, the values of is_fine are true and for m2, the values are false
I have two questions:
(1) for id mapping, I can map id and type as compound primary key for table AA. But then I do not know in hibenate how I can make a foreign key in table BB to refer to part of the compound primary key in AA. If I can make the id in AId as the primary key in table AA, that is also fine. But I do not know how to map that.
(2)for the two maps, if I use <map> with <composite-element> when persist instance of A, there should be no problem but there is no way to separate the rows in BB and break into two maps based on value of is_fine
Can some Hibernate expert show me how they can be done? or not possible at all?
Thanks in advance
|