hibernate-criteria

Hibernate Criteria Query to get specific columns

末鹿安然 提交于 2019-11-26 10:21:45
问题 I am using Criteria Query in my code. It always fires select * from ... Instead I want to neglect one column(field) from my query as that field have large number of data stored in bytes. And that causing performance issue. Can any one give an idea for that? Some Update I added a projection in my query and it created a query like... select this_.TEMPLATE_ID as y0_, this_.TEMPLATE_NAME as y1_, this_.CREATE_DATE as y2_, this_.UPDATE_DATE as y3_, this_.STATUS_CODE as y4_, this_.USER_ID as y5_,

How to transform a flat result set using Hibernate

时间秒杀一切 提交于 2019-11-26 08:34:22
问题 Is it possible to map result of SQL to not flat object? List<Customer> customers = hibernateSession().createCriteria(CustomerDetailsView.class) .add(Restrictions.in(\"userName\", userName)) .setProjection(buildProjection()) .setResultTransformer(Transformers.aliasToBean(Customer.class)) .list(); In my case CustomerDetailsView has flat structure. But I need to map it to object like this: public class Customer { private String userName; private String title; private String firstName; private

Criteria.DISTINCT_ROOT_ENTITY vs Projections.distinct

强颜欢笑 提交于 2019-11-26 03:55:45
问题 I am pretty new to Hibernate. I found out that we can get distinct result using following two different ways. Could any one tell me what is the difference between them? When to use one over other? Projections.distinct(Projections.property(\"id\")); vs criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); 回答1: While similar names, the usage is different. I. Projections.distinct(Projections.property("id")); this statement would be translated into SQL Statement. It will be passed to DB

JPA and Hibernate - Criteria vs. JPQL or HQL

断了今生、忘了曾经 提交于 2019-11-26 02:59:33
问题 What are the pros and cons of using Criteria or HQL? The Criteria API is a nice object-oriented way to express queries in Hibernate, but sometimes Criteria Queries are more difficult to understand/build than HQL. When do you use Criteria and when HQL? What do you prefer in which use cases? Or is it just a matter of taste? 回答1: I mostly prefer Criteria Queries for dynamic queries. For example it is much easier to add some ordering dynamically or leave some parts (e.g. restrictions) out