I'm used Spring DATA JPA from my web application. I'm goal working API REST crud method which using two tables from MySQL. Project is goal then DB has 2 tables: Item and AutoBrand, and they are association relationship. One item could get many autobrands than 1. But my app gets problem which autobrand table isn't find id from Item TABLE.
For example: Get localhost:8081/autoeshop/items - 200 OK Get localhost:8081/autoeshop/item/1/brands - 500 internal server error
System reported messages: Unable to locate Attribute with the the given name [id] on this ManagedType [com.autoparts.autoeshop.model.Item]; nested exception is java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [id] on this ManagedType [com.autoparts.autoeshop.model.Item]
My code: Item.java
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long itemID;
private String name;
private String provider;
private double price;
private int quantity;
@OneToMany( cascade = CascadeType.ALL, mappedBy = "item")
private Set<AutoBrand> brands;
AutoBrand.java
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long brandID;
private String name;
private String model;
private int year;
@ManyToOne
@JoinColumn(name="itemid", nullable = false)
private Item item;
Item rep.java
public interface ItemRepository extends JpaRepository<Item, Long> {
}
AutoBrand Rep.java
public interface AutoBrandRepository extends JpaRepository<AutoBrand, Long> {
}