0

I have defined a many-to-one relationship between my three entity classes catalogB, tableA and tableAB. tableAB has a primary key composite of tableA.tableAId and catalogB.catalogBId, and I used the following code:

@Entity
@Table(name = "tableAB", schema = Constantes.SCHEMA_SOLICITUD,uniqueConstraints = {@UniqueConstraint(columnNames = { "tableAId  ", "catalogBId" }) })
public class TableAB implements Serializable {

    private static final long serialVersionUID = 6360131240770014903L;

    @Id
    @ManyToOne(optional = false)
    @JoinColumn(name = "tableAId", referencedColumnName = "tableAId")
    private TableAId tableAId;

    @Id
    @ManyToOne(optional = false)
    @JoinColumn(name = "catalogBId", referencedColumnName = "catalogBId")
    private CatalogBId catalogBId;

And that gives me an error:

Caused by: java.lang.IllegalArgumentException: This class [schema.TableAB ] does not define an IdClass
Amarth Gûl
  • 1,040
  • 2
  • 14
  • 33

1 Answers1

0

Refer this question. The accepted answer as well as other answers shed light on what you are trying to achieve.

Meet K.
  • 459
  • 3
  • 15
  • That could help me,but he dont show the class "AssignedRoleId.class" – valex silva Jun 17 '20 at 22:43
  • Then refer [this question](https://stackoverflow.com/questions/3585034/how-to-map-a-composite-key-with-jpa-and-hibernate). It provides two approaches, `EmbededId` and `IdClass`. – Meet K. Jun 18 '20 at 16:19