Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Mapping a Database View

On Fri, Sep 11, 2009 at 10:54 AM, RogerV <roger.varley@xxxxxxxxxxxxxx> wrote:
where platformId, busId and txAddress form a unique identifier that is, in
fact the primary key of both underlying tables.
  1. Create an @Embeddable class that has these three fields in it.  This will end up being your Java class's composite primary key class.
  2. Mark each of those fields with the appropriate @Column annotation.  For example, one of your composite key member variables might be "businessID", in which case your @Column annotation would be @Column(name = "busId").
  3. Override its equals() and hashCode() methods so that two instances of this class are equal if and only if all three fields have equal values.
  4. With that done, go back to your main .java file and give it a field called, say, ID or PK or something similar.  Mark that field as being its @EmbeddedId.  Its type should be the type of the embeddable class you just created.
  5. Map that .java file using the @Table annotation to your view.
I hope this helps.

Best,
Laird

Back to the top