createcriteria

Hibernate 5 - createCriteria deprecated

我的梦境 提交于 2020-02-22 05:41:03
问题 I need a help to migrate the code with createCriteria for Hibernate 5 , the code is this below: public Curso comDadosIguais(Curso curso) { return (Curso) this.session.createCriteria(Curso.class) .add(Restrictions.eq("codigo", curso.getCodigo())) .uniqueResult(); } Could you help me? 回答1: There are a number of options you can exercise to migrate from the deprecated Hibernate Criteria API, these are just a few that immediately come to mind: HQL / JPQL Named query JPA Criteria API From a HQL /

Hibernate 5 - createCriteria deprecated

ぐ巨炮叔叔 提交于 2020-02-22 05:39:29
问题 I need a help to migrate the code with createCriteria for Hibernate 5 , the code is this below: public Curso comDadosIguais(Curso curso) { return (Curso) this.session.createCriteria(Curso.class) .add(Restrictions.eq("codigo", curso.getCodigo())) .uniqueResult(); } Could you help me? 回答1: There are a number of options you can exercise to migrate from the deprecated Hibernate Criteria API, these are just a few that immediately come to mind: HQL / JPQL Named query JPA Criteria API From a HQL /

hibernate - createCriteria or createAlias?

ぐ巨炮叔叔 提交于 2020-01-09 06:20:51
问题 If I want to search those students who take class "Math" and "John" is his group: shoud I use createCriteria or createAlias? Criteria: Criteria criteria = session.createCriteria(Student.class); Criteria subquery1 = criteria.createCriteria("courses", course).add(Restrictions.eq(course.name, "Math")); Criteria subquery2 = criteria.createCriteria("group", student).add(Restrictions.eq(student.name, "John")); how to put subquery1 and subquery2 together with initial criteria? Alias: Criteria

hibernate - createCriteria or createAlias?

若如初见. 提交于 2020-01-09 06:18:08
问题 If I want to search those students who take class "Math" and "John" is his group: shoud I use createCriteria or createAlias? Criteria: Criteria criteria = session.createCriteria(Student.class); Criteria subquery1 = criteria.createCriteria("courses", course).add(Restrictions.eq(course.name, "Math")); Criteria subquery2 = criteria.createCriteria("group", student).add(Restrictions.eq(student.name, "John")); how to put subquery1 and subquery2 together with initial criteria? Alias: Criteria

CreateCriteria with projections does not select all columns

十年热恋 提交于 2019-12-30 11:15:09
问题 My Question is exactly like Grails Projections not returning all properties and not grouped I have a following criteria def sharedDocumentsInstanceList SharedDocuments.createCriteria().list(params){ createAlias('receiver', 'r') createAlias('author', 'a') eq("r.id",session.uid) projections{ groupProperty("a.id") property("a.firstName","firstName") property("a.lastName","lastName") property("a.emailAddress","email") } } Where sharedDocuments is defined as follows class SharedDocuments { Users

Grails / GORM criteria query with hasmany String

我只是一个虾纸丫 提交于 2019-12-30 08:09:10
问题 I have a domain object (Cat) like this: class Cat { String name static hasMany = [ nicknames: String ] } (A cat has a name, and also has many nicknames (which are Strings)) And I am trying to query all the cats with certain nicknames. I've tried this: PagedResultList getCatsByNickname(String nickname, Map params) { PagedResultList results = Cat.createCriteria().list(params) { 'ilike'('nicknames','%'+nickname+'%') } return results } But it never returns any results. (If I change the query to

Is there a 'contains' functionality on a collection property of a domain object for createCriteria?

混江龙づ霸主 提交于 2019-12-29 08:29:11
问题 I have an Auction domain object and a User domain object. An Auction hasMany Users. What I'd like to do, using createCriteria , is something like this: def c = Auction.createCriteria() def l = c.list (max: maxVar, offset: offsetVar) { contains("users", thisUser) } Though, contains is not in the list of acceptable nodes: createCriteria description page. Is there any way to implement this functionality? To be clear, is there a way to have the criteria be that a specified User object is

NHibernate query CreateCriteria

懵懂的女人 提交于 2019-12-23 06:49:30
问题 Is it possible to chose what columns I want in return from Session.CreateCriteria() ? egz.: var x = session.CreateCriteria(); x.CreateAlias("EmployeePosition", "employeePosition"); x.Add(Restrictions.Eq("employeePosition.Name", "Developer")); and is there a way to add something like "select LastName" to avoid downloading the whole row. 回答1: make a class that has only the properties you need, often this is a summary class like {Id, Label} and you'd reuse it anywhere you need a simple type, in

Can I do a math operation inside a createCriteria

只谈情不闲聊 提交于 2019-12-12 03:53:40
问题 Is it posible to do a math problem inside a createCriteria? For example: If in my table I have two columns, if the two together make 100 I don't want to show it in my result of the query or if the other column is in other table? table column 1 column 2 50 50 20 20 I want the second row or table 1 table 2 50 50 20 20 回答1: One option would be to define a formula field in your domain class. Something like: class SumFormula { Integer column1 Integer column2 Integer sum static mapping = { sum

Load collections eagerly in NHibernate using Criteria API

会有一股神秘感。 提交于 2019-12-11 16:06:08
问题 I have an entity A which HasMany entities B and entities C. All entities A, B and C have some references x,y and z which should be loaded eagerly. I want to read from the database all entities A, and load the collections of B and C eagerly using criteria API. So far, I am able to fetch the references in 'A' eagerly. But when the collections are loaded, the references within them are lazily loaded. Here is how I do it AllEntities_A = _session.CreateCriteria(typeof(A)) .SetFetchMode("x",