Issue
Masalah ini terjadi ketika entity tidak memiliki @Id didalam entity, jadi di JPA mewajibkan dia memiliki @Id.
Solution
Solusinya mengganti @Id dengan @EmbeddedId dan membuat class baru untuk class Idnya yg menyimpan entity relationship dengan tipe data sesuai dengan column di database.
How To
Class Entity Id
@Embeddable @Data public class FilmCategoryId implements Serializable { private static final long serialVersionUID = -4161332004787248098L; @Column(name = "film_id", nullable = false) private Integer filmId; @Column(name = "category_id", nullable = false) private Integer categoryId; }
Class Entity
@Entity @Table(name = "film_category") @Data public class FilmCategory { @EmbeddedId private FilmCategoryId id; @MapsId("filmId") @ManyToOne(fetch = FetchType.LAZY, optional = false) @JoinColumn(name = "film_id", nullable = false) private Film film; @MapsId("categoryId") @ManyToOne(fetch = FetchType.LAZY, optional = false) @JoinColumn(name = "category_id", nullable = false) private Category category; @Column(name = "last_update", nullable = false) private Instant lastUpdate; }
Class Repository
public interface FilmCategoryRepository extends JpaRepository<FilmCategory, FilmCategoryId>, JpaSpecificationExecutor<FilmCategory> { }
Komentar
Posting Komentar