I have a problem with JPA.
I have tables:
----------------- | TableA | |---------------| | ID: INT | | ... | | ESTATUS1: INT | | ESTATUS2: INT | ----------------- ----------------- | EstatusTags | |---------------| | COD: VARCHAR |---> COD and VALUE are a concatenated PK | VALUE: INT | | DESC: VARCHAR | -----------------
EstatusTags is a table for storing sets of [VALUE, DESC] pairs, given COD.
Before using JPA, I used a query of this kind of data like this:
SELECT ID, ESTATUS1, ESTATUS2, E1.DESC DESC1, E2.DESC DESC2 FROM TABLEA A INNER JOIN ESTATUSTAGS E1 ON E1.COD = "a_estatus1" AND E1.VALUE = A.ESTATUS1 INNER JOIN ESTATUSTAGS E2 ON E2.COD = "a_estatus2" AND E2.VALUE = A.ESTATUS2
I am trying to use JPA to model this using two entity classes:
@Entity @Table(name = "EstatusTags") public class EstatusTags implements Serializable { @EmbeddedId private ValueTagPK id; @Column(name="VVA_DESC") private String desc; @Column(name="VVA_ORDEN") private Integer orden; } @Entity @Table(name = "TableA") public class A implements Serializable { @Column(name="ID") private String desc; @OneToOne(???) private EstatusTag estatus1; @OneToOne(???) private EstatusTag estatus2; }
I have strong doubts about how to model relationships. Can this be done with annotations? Is it necessary to use JPQL for this structure?
I hope someone can help me with this.
Many thanks.
source share