Hibernate: how to create saved filters and then use them?

This is the problem:

I get a job for a project that uses Spring, Hibernate, and Wicket.

On a certain HTML page, I should be able to create a filter (specify the filter name and its parameters). I have to create a filter list this way. At the same time, I should be able to edit and delete the filter, and of course, to use this filter.

Any ideas? How can i do this?

My experience with Hibernate is very low, but I need to come up with a project.

My naive solution:

I have a Table_Something class with which I linked a table in my database with Hibernate, and I need to create the ability for the user to create filters for this table in my web application

So, I would create a class called Table_Something_Filters, to which I will also associate a table in my database with Hibernate. Therefore, when I create a new filter for Table_Something in my application, I would enter a new row in my Table_Something_Filters.

Is that a good idea? Any improvements for my solution?

Another problem: how can I use my filter? I am querying Table_Something_Filters to get filter parameter values, and then what? How can I generate a search engine or how can I query Table_Something based on the values ​​from Table_Something_Filters?

Any ideas or suggestions are welcome! :)

+3
source share
1 answer

, , * _FILTER , , DAO , :

public List<MyEntity> findByFilter(MyEntityFilter filter) {
   //Use hibernate criteria api to build up your query depending on value in your filter
   Criteria criteria = session.createCriteria(MyEntity.class)

   if (filter.getName() != null) {
      criteria.add( Restrictions.like("name", filter.getName())
   }
   ... Go on testing and adding other parts of the query

   return criteria.list();

MyEntityFilter . , , , . , . , , : name = John; color = blue, red, yellow; parameter3 = value *, . , !

Filter.

spring hibernate, HibernateDaoSupport, , .

, api, HQL, api ( , ).

0

Source: https://habr.com/ru/post/1728819/


All Articles