Spring Data JPA内部联接与复合键

时间:2017-05-11 04:26:17

标签: java spring hibernate jpa

我有以下表格,具有指定的关系:

enter image description here

使用以下型号:

...
@AssociationOverrides({
    @AssociationOverride(name = "primaryKey.userId",
        joinColumns = @JoinColumn(name = "`userId`")),
    @AssociationOverride(name = "primaryKey.citaId",
        joinColumns = @JoinColumn(name = "`citaId`")) })
    public class UsuarioCita {


private UsuarioCitaPK primaryKey = new UsuarioCitaPK(); 

...

复合键:

@Embeddable
public class UsuarioCitaPK implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private User userId;
    private Cita citaId;

    @ManyToOne(cascade=CascadeType.PERSIST)
    public User getUserId() {
        return userId;
    }

    public void setUserId(User userId) {
        this.userId = userId;
    }

    @ManyToOne(cascade=CascadeType.PERSIST)
    public Cita getCitaId() {
        return citaId;
    }

在Cita模型中:

@OneToMany(mappedBy="primaryKey.citaId", cascade=CascadeType.PERSIST)
    private List<UsuarioCita> usuarioCita;

如何在这两个表之间用JPQL编写连接查询?由于UsuarioCita使用复合键。

0 个答案:

没有答案