criteria

Projection-Grouping-Detached Criteria

血红的双手。 提交于 2019-12-25 09:37:32
问题 public List<Staffing> upcoming(){ List<Staffing> staffing = new ArrayList<Staffing>(); Criteria criteria = getCriteria(); criteria.add(Restrictions.isNotNull("startDate")).add(Restrictions.le("startDate", new Date())); criteria.add(Restrictions.isNotNull("endDate")).add(Restrictions.ge("endDate", new Date())); criteria.add(Restrictions.eq("softDelete", false)); criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("user"))); DetachedCriteria maxDateQuery =

Projection-Grouping-Detached Criteria

无人久伴 提交于 2019-12-25 09:37:06
问题 public List<Staffing> upcoming(){ List<Staffing> staffing = new ArrayList<Staffing>(); Criteria criteria = getCriteria(); criteria.add(Restrictions.isNotNull("startDate")).add(Restrictions.le("startDate", new Date())); criteria.add(Restrictions.isNotNull("endDate")).add(Restrictions.ge("endDate", new Date())); criteria.add(Restrictions.eq("softDelete", false)); criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("user"))); DetachedCriteria maxDateQuery =

How to join tables using hibernate criteria

人盡茶涼 提交于 2019-12-25 05:07:35
问题 I am trying to join multiple table to join using criteria but getting error in doing so can someone please help me in it My code is final Session session = getSession(); final Criteria criteria = session.createCriteria(ReferralPaymentInfo.class).createCriteria("SIGNUP_REFERRAL"); System.out.println("before"); List list = criteria.list(); System.out.println("after"); I also tried this code final Session session = getSession(); final Criteria criteria =session.createCriteria(ReferralPaymentInfo

How to join tables using hibernate criteria

牧云@^-^@ 提交于 2019-12-25 05:07:13
问题 I am trying to join multiple table to join using criteria but getting error in doing so can someone please help me in it My code is final Session session = getSession(); final Criteria criteria = session.createCriteria(ReferralPaymentInfo.class).createCriteria("SIGNUP_REFERRAL"); System.out.println("before"); List list = criteria.list(); System.out.println("after"); I also tried this code final Session session = getSession(); final Criteria criteria =session.createCriteria(ReferralPaymentInfo

org.hibernate.QueryException: Criteria objects cannot be created directly on components

纵然是瞬间 提交于 2019-12-25 04:27:44
问题 I face above issue when try to sort based on an embedded field; eg: I try to sort with the property tObservation.raw.waterLevel.metre . But getting following exception. Caused by: org.hibernate.QueryException: Criteria objects cannot be created directly on components. Create a criteria on owning entity and use a dotted property to access component property: tObservation.raw at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathInfo(CriteriaQueryTranslator.java:251) I create aliases

Hibernate criteria restriction on a property for all elements of a set

北城以北 提交于 2019-12-25 01:46:41
问题 I have an entity with a set say like Library---><Set>books Now I want to retrieve the libraries where ALL the books have a genre. So I have something like this: c.createCriteria("library", "library").createCriteria("books", "book"); c.add(Restrictions.isNotNull("book.genre")); If I execute the query I get the libraries where at least one book has a genre but I'd like hibernate to check the genre property for all the elements of the book set and return the libraries where ALL the elements

How to compare datepart Month using Nhibernate Criteria?

对着背影说爱祢 提交于 2019-12-25 01:28:53
问题 This is my code: public IList<VotacaoPlenario> RetornarVotacao(int mesInicio, int anoInicio) { DetachedCriteria criteria = DetachedCriteria.For<VotacaoPlenario>(); if (anoInicio > 0) { criteria.Add(Expression.Eq("YEAR(Data)", anoInicio)); } IList<VotacaoPlenario> votacao = criteria.GetExecutableCriteria(Session).List<VotacaoPlenario>(); return votacao; } } In my table de field Data is Datime i'm need to compare with the variable anoInicio which is int How can i do that? 回答1: The solution here

How to construct advanced Hibernate Query with OR and summarize functions

回眸只為那壹抹淺笑 提交于 2019-12-24 09:40:24
问题 I have a rather complex query which works in SQL, but I would like to express this in HQL for portability. I'm going to fetch a user configured preference value if they exist, if not I must use a default value. This value must be subtracted from current date and the matched against a column in the table which I'm interested in: select d.id, d.guid, d.deletetimestamp, u.id from descriptor d, ownerkey ow, user u where d.parentid in (select td.id from descriptor td, store s where s.type = 'Trash

Hibernate Criteria API condition “like” with integer

六眼飞鱼酱① 提交于 2019-12-24 07:17:13
问题 In my database I have a column "year" which is an integer. How can I search by using Criteria API (not by HQL) which records contain, for example "196..." in the year column? I think it should be Restrictions.like , but I got exception: SEVERE: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer 回答1: a better and faster solution would be to use Criterion.sqlRestriction(String sql). You can form the sql as, "to_char(year) like '19%'", be aware that to_char is

Criteria addOrder to order by trim(field)?

杀马特。学长 韩版系。学妹 提交于 2019-12-24 06:43:40
问题 All is in this question, here is my method. public List<Object> listEntry(final int rowNumMin, final int maxResult, final String orderField, final int orderSort) { final Criteria requete = getSession().createCriteria( getPersistentClass()); if(orderSort=1){ requete.addOrder(Order.asc(orderField)); } else { requete.addOrder(Order.desc(orderField)); } requete.setMaxResults(maxResult); requete.setFirstResult(rowNumMin); final List<Object> resultat = requete.list(); return resultat; } This is