0

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> {

}
  • 1
    Post the exact and complete stack trace of the exception. It probably has nothing to do with JPA. – JB Nizet Oct 16 '18 at 20:16

1 Answers1

0

maybe your getter is getId instead of getItemID see Spring Data JPA Unable to locate Attribute with the the given name

anyway would be better to post as much of the code as you can

Bashar Ali Labadi
  • 1,014
  • 1
  • 11
  • 19
  • I have changed into `getItemID` and getting error: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'autoBrandController': Unsatisfied dependency expressed through field 'autoDAO'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: – Lukas Gužauskas Oct 16 '18 at 21:03
  • I'm not sure, can you update the question with more code (controller, dao etc) because it seems that your dao is missing some bean – Bashar Ali Labadi Oct 16 '18 at 21:26