简体   繁体   中英

Java Hibernate field access property or property based access

i am developing some improvements over a legacy system have some quite time

i have a class like this

class MyPersistentClazz
{
      private String aTPlace;
      public void setATPlace(.......){......}//yes mistyping    
      @Column(name="atPlaceOrder")
      public String getATPlace(){return aTPlace;}
}

they usually load this class using this methods

final MyPersistentClazz clazz = (MyPersistentClazz)session.createCriteria(MyPersistentClazz.class).add(idEq(id)).uniqueResult();

and using load and get methods and works OK.

but the problem arise when i use projections.

final Projection p=Projections.projectionList().add(Projections.property("d.aTPlace"),"aTPlace");

throws

Exception in thread "main" org.hibernate.QueryException: could not resolve property:

my question is...

when using projections i think Hibernate is calling the setter of each property is this assertion OK?

when using criteria.uniqueResult or load or get Hibernate use individual field property access?

or why works with some and not work with others with the same setter?

we are using only annotations not XML.

thanks a lot.

How Hibernate works with your bean depends on how you annotated it. If you annotate instance variables then Hibernate will use direct injection and bypass your Set methods. Otherwise, it will use your Set methods.

Could it be that it is incorrectly converting your property name to a Set method name? Try changing the property name to something simpler (without that series of capital letters), and ensure that the case of the property in your projection is correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM