Sleep mode and how to avoid modal name changes

I have been using Hibernate for several years, but am not sure about the use of queries and criteria.

I realized that one of the strengths of Hibernate is to control the field name in one place. If I have the following code:

List cats = sess.createCriteria(Cat.class) .add( Restrictions.like("name", "Fritz%") ) .add( Restrictions.between("weight", minWeight, maxWeight) ) .list(); 

What if I change the "name" of the Cat in a java object?

Even when using a refactor replacement (e.g. in Elipse), it will not detect the element as something that needs to be changed!

If so, how do you maintain field names in Java?

+6
source share
2 answers

I am sure that safe type requests are not supported in Hibernate, a specific api. However, JPA 2 supports it. Read this: Dynamic, typed queries in JPA 2.0

+3
source

I have the same problem in the past, and there really is no way to have a typed and refactored (change name) field link in java, so it's not possible to create a query builder that allows this, but I tried to build a query builder implementation using some workaround The solution is to allow you to write a safe type and refactoring query, this is the name of ObjectQuery, and you can find some information about.

let me know if he decides your use case!

obviously nothing standard, so if you are looking for something standard, JPA Typesafe is better, but it does not have the same power!

0
source

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


All Articles