java实体外键_java – 实体的Spring Data Repository,其中外键也是主键

我在使用JPA2(

EclipseLink)和Spring Data 1.4.2时遇到了一些问题.

在我的例子中,两个表具有一对一的关系:

表A:

> aId(PK)

> ……

表B:

> bId(PK,FK – 映射到TableA中的aId)

> ……

所以我试着做这个实体:

EntityA:

@Entity

@Table(name = "TableA")

public class EntityA implements Serializable {

@Id

@GeneratedValue

@Column(name = "aId")

private Long id;

// another fields and getter/setter/business methods

...

}

EntityB:

@Entity

@Table(name = "TableB")

public class EntityB {

@Id

@OneToOne

@JoinColumn(name = "bId", referencedColumnName = "aId")

private EntityA id;

// another fields and getter/setter/business methods

...

}

EntityA的Spring Data Repository运行良好:

@Repository(value = "aRepository")

public interface RepositoryA extends CrudRepository {

}

但对于EntityB:

@Repository(value = "bRepository")

public interface RepositoryB extends PagingAndSortingRepository {

}

抛出异常:

Expected id attribute type [class java.lang.Long] on the existing id attribute [SingularAttributeImpl[EntityTypeImpl@5270829:EntityA [....] but found attribute type [class EntityB].

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值