I'm trying currently to map the following schema (simplified to just the columns participating in the relations) to the following classes (also simplified), using annotations:
Code:
create table Domain (
id integer primary key
)
create table Category (
domain integer,
id integer,
primary key (domain, id),
foreign key (domain) references Domain (id)
)
create table Item (
domain integer,
id integer,
category integer,
primary key (domain, id),
foreign key (domain) references Domain (id),
foreign key (domain, category) references Category (domain, id)
)
Code:
class Domain {
Integer id;
}
class Category {
Domain domain;
Integer id;
}
class Item {
Domain domain;
Integer id;
Category category
}
So far my problems seem to be two:
One, I have a many-to-one relationship in my primary key. An hour's searching has told me that EJB2 didn't support @Id and @ManyToOne in its spec, hibernate might have, end EJB3 was supposed to. Also that by using update="false" insert="false" in some way I can get it to work, but I haven't actually found a description of the method. This isn't a serious problem in the end, however, since I'm willing to drop the Domain table and class and all the attributes they contain. As it stands, however, the domain column is being generated as a blob, which just isn't right.
Two, whether I drop Domain's attributes or not, there's still the sharing of the domain column between the foreign key and primary key. It seems like I should just be able to specify @JoinColumns, but I'm honestly not sure how Hibernate would handle it. And combining the solution to this problem to the previous is beyond my experience.
Thank you for your consideration, hopefully a solution will be found so I don't have to drop Hibernate.