0

I have this 3 entities E1, E2, E3. I want to know how I must note my E3 class has 2 primary key each pointing to a different table with additional fields.

@Entity
public class E1 extends RAP{
    /**
     * 
     */
}

@Entity
public abstract class E2{
    /**
     * 
     */
}

E3 class has 2 primary keys pointing to e1 and e2.

@Entity
public class E3 extends RAP{
    @Id
    @ManyToOne  
    @JoinColumn(name = "e1_id")
    private E1 e1;

    @Id
    @ManyToOne
    @JoinColumn(name = "e2_id")
    private E2 e2;

    private Double myfield1;
    private Double myfield2;
}

but there is a problem. like this...

This class has a composite primary key. It must use an ID class.

so i want to use some annotation without using @Embedded entity

isom
  • 304
  • 1
  • 13

1 Answers1

1

Here you have an example of how to specify constraints over multiple columns, and how declare relations between tables, also check this to have a reference about indexing in jpa 2.0, and the main differences with 2.1.

You problem looks like a perfect candidate for a hierarchical model and this link shows an example of how define and use this kind of models.

If you can explain what you want to archive a bit more, maybe we can find a more specific solution.

Community
  • 1
  • 1
Javier Toja
  • 1,630
  • 1
  • 14
  • 31