我在三个实体类catalogBtableAtableAB之间定义了多对一关系。 tableAB具有tableA.tableAIdcatalogB.catalogBId的主键组合,我使用以下代码:

@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;


这给了我一个错误:

Caused by: java.lang.IllegalArgumentException: This class [schema.TableAB ] does not define an IdClass

最佳答案

请参阅this question。接受的答案以及其他答案为您要实现的目标提供了启示。

08-26 01:21