문제

I'm confused with the criteria Restriction field naming on Hibernate when we apply a condition. I have a database table called "User" and it contains a field called "status_id". I have used the eclipse hibernate tools to generate the POJOs and it created the User class and the property name is "statusId" within the class, which does not have the "_" sign.

Now I want to know in the following code, which name I have to use for the Restriction criteria.

Criteria criteria = session.createCriteria(User.class)
                 .add(Restrictions.eq(<column to check>, new Int(1)));

My confusion is whether to use the "status_id" or the "statusId" in the column to check for the criteria. I searched for the explanation and couldn't find similar problem. Can someone help me out in this issue?

도움이 되었습니까?

해결책 2

You use the bean property name. If your column is status_id and you have int statusId in your class, the property name for the criteria is the name of the bean property: statusId

This generates SQL and will figure out your query needs to be status_id

http://docs.jboss.org/hibernate/orm/3.5/javadocs/org/hibernate/criterion/Restrictions.html

다른 팁

@Column(name = "DEPT_NAME", length = 100)

private String DEPTNAME;

Here DEPT_NAME is supposed to be used when using native sql

DEPTNAME is used when using HQL and during criteria.

Use statusId. You always use field names from the mapped POJOS and not the table column names unless you are trying to write a SQL.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top