Create selects with hibernate criteria generic

0

I'm doing a web-based, administrative software, it has several graphs and several tables, the problem with this is that several graphs and tables generate many queries to the database, and with this, many classes that have a similar structure, For example, for the graphs all have the date attribute, an array of integers or dates, I would like to write a more elegant code, so that with only one repository class I could bring the date values generically, I even created a single class using the Generics java that does the basic operations for each entity of the bank (select, update, delete, list ...), it was much better, works well and reduced me some 500 lines of code (there are 18 entities ...) I would like to do something like that for the dates.

As I'm new to hibernate, I'm having trouble visualizing how I can do this generically, there might be an API that already does this ... I accept anything to improve the code. And of course, is this a good option? to implement a generic class for all graphics or one class for each?

    
asked by anonymous 13.12.2016 / 14:14

1 answer

1

There is uaiCriteria , a Framework for JPA. I do not think it's a complete solution to your problem, but it's an alternative to simplifying the code.

For example, to get a list of Pessoa with the name José :

final UaiCriteria uaiCriteria = UaiCriteriaFactory.createQueryCriteria(entityManager, Pessoa.class);
uaiCriteria.andEquals("nome", "José");
final List uaiCriteriaResult = uaiCriteria.getResultList();
    
13.12.2016 / 21:27