单向ManyToOne复合键

时间:2018-12-21 22:25:22

标签: java spring hibernate

我想为我的一张桌子创建复合主键。我试图使用@Embededdable@EmbededdId,但是没有用。另外,我需要将两个字段的sa分别标记为@ManyToOne。 我的复合键。

@Embeddable
class OwnedCryptocurrencyIdentity implements Serializable{

    @ManyToOne
    @JoinColumn(name = "cryptocurrency_id")
    private Cryptocurrency cryptocurrency;
    @ManyToOne
    @JoinColumn(name = "user_id")
    private User user;

我要在其中嵌入组合键的类:

@Entity
class OwnedCryptocurrency implements Serializable{
    private double amount;

    @EmbeddedId
    private OwnedCryptocurrencyIdentity ownedCryptocurrencyIdentity;

我已经尝试ManyToOne relation with composite key这一项了(但没有用)。我也尝试了我在谷歌找到的链接之一。 错误是:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: pl.kamil.larysz.marketsimulatorv2.user.domain.OwnedCryptocurrency.user

0 个答案:

没有答案