Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate and how to avoid name change of modals

I am using Hibernate for a few years but am not sure about the usage of Query and Criteria.

I understood, that one of Hibernate strengths are 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 "name" of the Cat in the java object?

Even when using refactor replace (like in Elipse) it will not detect the element as something that needs to be changed!

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

like image 764
Dejell Avatar asked Jan 18 '12 16:01

Dejell


1 Answers

I believe type safe queries are not supported in Hibernate specific api. JPA 2 however has support for it. Read this: Dynamic, typesafe queries in JPA 2.0

like image 67
Aravind Yarram Avatar answered Nov 13 '22 09:11

Aravind Yarram