Andrey
Andrey

Reputation: 696

JPA 2.0 map one class to different columns of one table

i have Entity mapped to table TABLE1 with columns COLUMN1 and COLUMN2

i have class ResViewer

public class ResViewer() {
  private boolean flag;
  private int property;

  ...selectors

}

i have entity class

@Entity
@Table(name="TABLE1")
public class Table1() {

    @Id
    private long id;

    private ResViewer res1;
    private ResViewer res2;

    ...selectors

}

How can i map field flag of classes res1 and res2 to columnds COLUMN1 and COLUMN2?

Upvotes: 1

Views: 673

Answers (1)

JB Nizet
JB Nizet

Reputation: 691635

Your ResViewer needs to be annotated with @Embeddable, and the fields res1 and res2 must be annotated with @Embedded, and with @AttributeOverrides, as demonstrated in the javadoc of @Embedded.

Upvotes: 3

Related Questions