I have some problems with JPA2 (EclipseLink) and Spring Data 1.4.2. In my case two tables has one-to-one relation:
TableA:
- aId (PK)
- ...
TableB:
- bId (PK, FK - maps to aId in TableA)
- ...
so I tried to do this entities:
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
...
}
Spring Data Repository for EntityA works well:
@Repository(value = "aRepository")
public interface RepositoryA extends CrudRepository<EntityA, Long> {
}
but for EntityB:
@Repository(value = "bRepository")
public interface RepositoryB extends PagingAndSortingRepository<EntityB, EntityA> {
}
throws Exception:
Expected id attribute type [class java.lang.Long] on the existing id attribute [SingularAttributeImpl[EntityTypeImpl@5270829:EntityA [....] but found attribute type [class EntityB].
OneToOne
annotation inEntityB
, thenid
inEntityA
is expected to beEntityB
type. – Octosyllabic@MapsId
to the@OneToOne
annotation inEntityB
:@OneToOne @MapsId
. – Octosyllabic