I am using spring and hibernate together.
Can any body suggest me how can i execute a simple query?
For example, I want to execute "select count(*) from USER_DETA开发者_如何学CILS";
Thanks,
NarendraHiii... Use criteria and projection together. Projection
Criteria crit = session.createCriteria(USER_DETAILS.class);
ProjectionList projList = Projections.projectionList();
projList.add(Projections.countDistinct("Id"));
crit.setProjection(projList);
crit.list will give you count. This is simple hibernate code you can figure out spring + hibernat with this example.
Hibernate is a Object-Relational Mapping tool. You first map a User object to USER_DETAILS table and then you write HQL (Hibernate Query Language) against the mapped User object (not USER_DETAILS table). For e.g you can write the query you have posted as below using HQL.
select count(user) from User user;
精彩评论