我在使用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].