Filter in OneToMany mapping (Spring)

0

I searched the internet but, I could not understand very well how I would do this using the Hibernate filters. Well, come on:

I have a OneToMany:

@OneToMany(mappedBy = "pedido", cascade = CascadeType.ALL)
@Getter
private final List<PedidoItem> pedidoItemProducao = new ArrayList<>();

I can get the data normally, I can filter using the @Where annotation and everything else. However, I would like to pass parameters to filter this data and @Where does not suit me, because the parameter would depend on what would come from the front.

Example:

pedidoRepository.findAll();

In this findAll, I would pass some parameter so that all the items of that request would not come. I already tried to filter using join and the whole thing, but in the end, it ends up bringing my object Request, which in turn has all the items bound to it.

What I wanted was to bring in the OneToMany mapping there, only "RequestItem" objects that had an X status and were of a production type Y, as in @Where, except that passing those X and Y values depending on the that came from my front.

Anyway, I did not find any way to do this using join or @Where, would you have any idea how I could do this?

    
asked by anonymous 20.07.2017 / 02:41

1 answer

0

You can use the Query interface to solve. Using HQL, it would look something like:

Query q = sessionFactory.openSession().createQuery("from MinhaClasse c where c.pedidoItem.status = :status");
q.setString("ABERTO");
return q.list();
    
20.07.2017 / 18:18