开发者

Entities with Foreign Key references to phantom tables & entities

I have an existent legacy DDL which I've to map onto JPA.

I've already mapped the USERS SQL table to an USERS JPA @Entity.

create table USERS (
  -- a bunch of fields
  primary key (id),
  foreign key FK_USERS_CONTACT (CONTACT_ID) references CONTACTS(ID),
  foreign key USER_SPEAKS_NATIVE_LANGUAGE (NATIVE_LANGUAGE) references LANGUAGES(ID),
  foreign key USER_HAS_PREFERRED_TIMEZONE (PREF_TIMEZONE_ID) references TIME_ZONES(ID),
  foreign key USER_OWNS_USAGE (USAGE_OWNER_ID) references USAGE_OWNERS(ID)
);

But there are those FKs to existent开发者_StackOverflow中文版 SQL tables that I don't want to depict in any JPA classes. The best solution would be to do the following:

@OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
@JoinColumn(nullable = false, name = "USAGE_OWNER_ID")
private Object usageOwners;

...basically to use a dummy/phantom Object that could reflect any table reference. But the raw Object type isn't allowed in JPA.

So how can I depict & fulfill the Foreign Key constraints of the USERS table without depicting any SQL tables in JPA. I just want to depict the FK references to those tables but not the actual SQL tables.


You would be best off having a Contact, Language, TimeZone, UsageOwner class. If you do want to have classes, then you could just have a @Basic mapping for the foreign key and map it as a basic type such as Integer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜