JPA - OneToOne Foreign key as primary key

2019-04-16 12:19发布

I have a table which requires its primary key as a foreign key to other table, so an unidirectional one-to-one relationship. There will be only an author per book, like this:

@Entity
public class Author {
    @Id
    String code;

    //getters and setters ...
}


@Entity
public class Book {
    @Id
    @OneToOne
    @JoinColumn(name="code", columnDefinition="DOM_COD5")
    Author author;

    //getters and setters
}

With plain Hibernate and JPA annotations it works well, but using using it through Spring Data I keep getting this error:

Caused by: java.lang.IllegalArgumentException: This class [class com.xxxx.api.catalogo.domain.Book] does not define an IdClass  

0条回答
登录 后发表回答