Entity Repository Spring Error with Relationships

Asked

Viewed 105 times

2

I have a project using Spring Boot to serve JSON on a Webservice. An error occurred when adding the Repository class. If you remove it the program starts normally (no errors in the console, I don’t mean features).

The mistake is: http://www.cjoint.com/c/FGir7xhZgvR (I put it on Cjoint because it’s too big).

Classes are:

@RepositoryRestResource
public interface Sells extends PagingAndSortingRepository<Long, Sell> {

}

@Entity
public class Sell implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private Date sellDate;
    @OneToMany(mappedBy = "sell", targetEntity = SellItem.class,
        fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    private List<SellItem> sellItems;
    private Double total;
    // Getters e setter omitidos
}

@Entity
public class SellItem implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @ManyToOne
    private Product product;
    private Integer quantity;
    @ManyToOne
    @JoinColumn(name = "sell_id")
    private Sell sell;
    //Getters e setter omitidos
}

If necessary, ask for more information in the comments.

1 answer

0

Hello, I don’t know if you have already identified your problem. I took a look at the error and saw that you declared your Restpository as follows:

public interface Sells extends PagingAndSortingRepository<Long, Sell> {
}

Since the correct way is:

public interface Sells extends PagingAndSortingRepository<Sell, Long> {
}

It seems to me you just reversed the order of the generic arguments of the interface Pagingandsortingrepository.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.