criteria

Is there any easy way to convert Criteria to HQL?

邮差的信 提交于 2019-11-30 18:12:01
I have posted a question few days ago about Querying on collections with the Criteria API and after all the answers I see that the thing that I am trying is not possible with the Criteria, there is a bug for the situation in nhibernate and also in hibernate I was using DetachedCriteria to get all criterias together and the list is really long. The last circle of chain is buggy criteria so I need to change all my detachedcriteria to HQL. So my question is is there any tool or way to convert Criteria to HQL. or Is there any way to get Criteria and Hql work together? An Article about the bug in

Hibernate Criteria Order By

[亡魂溺海] 提交于 2019-11-30 18:03:04
I have a table called Gift, which has a one-to-many relationship to a table called ClickThrough - which indicates how many times that particular Gift has been clicked. I need to query for all of the Gift objects, ordered by ClickThrough count. I do not need the ClickThrough count returned, as I don't need anything done with it, I just want to use it for purposes of ordering. I need the query to return a List of Gift objects directly, just ordered by ClickThrough count. How do I do this using the Criteria API? I can find a lot of documentation out there on similar information to this, but

Hibernate criteria query with subquery joining two columns

巧了我就是萌 提交于 2019-11-30 17:40:52
I have a table, "Quote", mapped in hibernate that has a composite key of an integer id and a date, and several additional columns. I'd like to write a criteria query that uses a DetachedCriteria to get the row for each id with the greatest date. In sql, I might write a query like SELECT * FROM Quote q1 INNER JOIN (SELECT id, max(date) as maxdate FROM Quote GROUP BY id, date) q2 ON q1.id = q2.id AND q1.date = q2.maxdate In hibernate, I think can create a DetachedCriteria for the "group by" subquery like this (where Quote is the class mapping the table, and "Qid" is a composite id class for the

Is there any easy way to convert Criteria to HQL?

狂风中的少年 提交于 2019-11-30 16:41:16
问题 I have posted a question few days ago about Querying on collections with the Criteria API and after all the answers I see that the thing that I am trying is not possible with the Criteria, there is a bug for the situation in nhibernate and also in hibernate I was using DetachedCriteria to get all criterias together and the list is really long. The last circle of chain is buggy criteria so I need to change all my detachedcriteria to HQL. So my question is is there any tool or way to convert

Hibernate的查询分页 by Criteria

ぐ巨炮叔叔 提交于 2019-11-30 16:08:07
当初学Hibernate的时候,带我的那个人说要学好Hibernate的hql语句,没有就没有QBC当做一会事儿 后来做项目的时候发现QBC还是蛮强大的 通常做分页都会讲一些数据封装到PageBean中, private int currentPage;//定义当前页 private int pageSize;//定义页面大小 private int total;//总纪录数 private List rows;//返回数据 private DetachedCriteria detachedCriteria;//Criteria离线查询接口 private int start//查询的起始值 将get的返回值设置为 (currentPage-1)*pageSize 在Dao层添加实现 public void pageQuery(PageBean pageBean){ //在请求页面发起时 前端会传来一个 页数 页面大小和相关的查询条件设置给pageBean //我们可以首先获取前端传来的参数 int currentPage=pageBean.getCurrentPage(); int pageSize=pageBean.getPageSize(); DetachedCriteria detachedCriteria=pageBean.getDetachedCriteria(); /

setResultTransformer in Criteria

感情迁移 提交于 2019-11-30 13:42:40
问题 What is the use of setResultTransformer method in criteria API? Can someone explain this with a simple example? I read the javadocs but i am not able to understand them clearly. Regards, 回答1: The default ResultTransformer for a Criteria query which does not use setProjections() will be ROOT_ENTITY . If we have Student in a ManyToMany relationship to Department a query might look like this ... Session session = (Session) getEntityManager().getDelegate(); Criteria crit = session.createCriteria

how to write Hibernate Criteria to take nested objects by Projection List?

China☆狼群 提交于 2019-11-30 13:01:50
问题 I want to take Nested object values in Hibernate Projection List. I having Pojo 'Charge' and 'Tariff' class with OneToMany and ManyToOne relations. My sample code is as following: Charge private String id; private Tariff tariff; private String name; @OneToMany(cascade= {CascadeType.ALL},fetch=FetchType.EAGER,mappedBy="charge") public Tariff getTariff() { return tariff; } public void setTariff(Tariff tariff) { this.tariff = tariff; } Tariff private String id; private String amount; private

(Lazy) LEFT OUTER JOIN using the Hibernate Criteria API

谁说胖子不能爱 提交于 2019-11-30 12:47:16
问题 I want to perform a LEFT OUTER JOIN between two tables using the Criteria API. All I could find in the Hibernate documentation is this method: Criteria criteria = this.crudService .initializeCriteria(Applicant.class) .setFetchMode("products", FetchMode.JOIN) .createAlias("products", "product"); However, this either performs an inner join or a right outer join, because of the number of results it returns. I also want my join to be Lazy. How can I do this? Cheers! UPDATE: It seems that using

How to insert an “Optimizer hint” to Hibernate criteria api query

六眼飞鱼酱① 提交于 2019-11-30 09:39:13
i have a hibernate query that is dynamically put together using the criteria api. it generates queries that are unbearably slow, if executed as-is. but i have noted they are about 1000% faster if I prepend /*+ FIRST_ROWS(10) */ to the query. how can i do this with the criteria api? i tried criteria.setComment(..), but this seems to be ignored. in the hibernate docs, 3.4.1.7. Query hints are mentioned, but it clearly states: "Note that these are not SQL query hints" the result of the query will be paginated, so in 99% of the cases i will display the results 1-10. You could modify the optimizer

SetFetchMode call ignored

微笑、不失礼 提交于 2019-11-30 09:24:54
问题 I have a problem with SetFetchMode call in Criteria API in following query: DetachedCriteria.For<User>() .Add<User>(u => u.Status == UserStatus.Live) .CreateAlias("UniqueId", "uid") .CreateAlias("Companies", "comp") .Add(Restrictions.Disjunction() .Add(Restrictions.Like("uid.Uid", context.Text, MatchMode.Anywhere)) .Add(Restrictions.Like("comp.Name", context.Text, MatchMode.Anywhere))) .SetFetchMode("Companies", FetchMode.Eager)); My Classes: public class User : EntityBase<int> { public