Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Help for extending compound key?

Hi,

Many of the tables that the people in my group deal with have a compound key
with five columns (call them A through E).

Several other tables have compound keys with six or more columns, A through E, plus additional columns. The typical usage is to add an additional column F.

We create an @Embeddable class (call it AE) for columns A through E, and use an
@IdClass annotation in entity classes that use A through E as primary key.

We can do a similar thing for tables that have six or more columns, but we'd
like to reuse class AE as much as possible. Does anyone here deal with this issue? What solutions are commonly used?

The best we've thought of so far is to create other @Embeddable classes for the most common ways of extending A through E with an additional columns. The constructors of these other @Embeddable classes take an AE instance as an argument. But each other @Embeddable class has instance variables for each of the columns A through E, plus one or more additional fields (for F, and if present G, H, etc.). So there ends up being a lot of code duplication, and we'd like to avoid this.

We've tried extending AE with another class, call it AF, that is also @Embeddable and that adds an additional instance variable for column F. The JPA 3.0 spec indicates this should be possible (if I read the spec right), but this hasn't worked for us. We're not particularly fond of this approach (it doesn't make good OO sense in the context of the project), so if turns out to be unsupported we won't be too disappointed.

If you have ideas or know of commonly-used solutions for similar situations, I'd be interested in hearing them.

Thanks a lot,
Ben



Back to the top