DetachedCriteria

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",

Hibernate java Criteria query for instances with multiple collection members like tag

China☆狼群 提交于 2019-12-11 13:39:18
问题 Please help me write a Java Criteria-object query to find all items with collections that have all desired members. Basically, I need to "and" the condition, not "or" it. This is exactly like SO articles and tags: search for articles with tags "java" and "hibernate", the result should only have articles tagged with both tags (more tags are ok). Like this one :) My entity is called "Solution" and it has a collection of tag entities mapped via a two-column mapping table. I understand from

convert criteria to detached criteria for self join

◇◆丶佛笑我妖孽 提交于 2019-12-11 12:33:21
问题 I would like to know if i can convert this criteria into a detached criteria. I am not understanding detached criteria correctly. can some one help. Criteria crit = sessionC.createCriteria(OP_DOCTOR_VISIT.class, "OPDV1"); crit.createAlias("OPDV1.OP_VISIT", "OPDV2", JoinType.LEFT_OUTER_JOIN, Restrictions.and(Restrictions.eq("OPDV2.FORM", "NEW"), Restrictions.ge("OPDV2.USER_DATETIME", fromdate), Restrictions.le("OPDV2.USER_DATETIME", todate))); crit.add(Restrictions.ge("OPDV1.USER_DATETIME",

JPA 2 Remote Criteria?

北城余情 提交于 2019-12-11 09:15:38
问题 Is there any way that criteria for queries can be built on a remote (Swing/SWT etc) client? We've been using the DetachedCriteria functionality in Hibernate for quite some time, but would like to use standard JPA 2. If not, could the code from hibernate be re-factored to create the remote API? Or is this something that might come along in JPA 2.1? 回答1: Not to my knowledge. Consider leaving a comment on Linda DeMichiel's Blog (the spec Lead) or sending your input to the expert group: JPA.next

NHibernate SetFetchMode doesn't work with nested criteria

末鹿安然 提交于 2019-12-11 05:25:05
问题 Assuming I run the following code: var placementCriteria = DetachedCriteria.For<ResidentialPlacementClientService>(); placementCriteria.Add(Restrictions.Le("StartDate", effectiveDate)); placementCriteria.Add(Restrictions.Ge("EndDate", effectiveDate)); placementCriteria.SetFetchMode("CaseClient.CaseFile", FetchMode.Eager); placementCriteria.SetFetchMode("CaseClient.Incomes", FetchMode.Eager); placementCriteria.SetFetchMode("CaseClient.ClientProfile", FetchMode.Eager); placementCriteria

grails 3.3 gorm where query with projection count() different than list().size()

与世无争的帅哥 提交于 2019-12-10 18:26:42
问题 According to the Gorm 6 documentation section 7.4 the Where Query returns a DetachedCriteria , which provides a method count() that is supposed to return the number of records returned by the query. In fact, as far as I can tell, if dc is an instance of DetachedCriteria , then dc.count() == dc.list().size() must hold true. In the case of a Where Query containing a projection, count() seems to return something else. In this simple example: query = Runner.where { projections { groupProperty

NHibernate: Convert an ICriteria to a DetachedCriteria

笑着哭i 提交于 2019-12-07 17:04:09
问题 Anyone know how to convert an ICriteria into a DetachedCriteria. I need to use an existing ICriteria as part of a subquery using: .Add(Subqueries.PropertyIn("Name", myDetachedCriteriaSubquery)) Is there any way to convert an ICriteria to a DetachedCriteria. I will accept 'no' with a credible reference. 回答1: Following on from mattk's answer, you can inherit DetachedCriteria to access its constructors: public class ConvertedDetachedCriteria : DetachedCriteria { public ConvertedDetachedCriteria

Hibernate DetachedCriteria multiple results in java

拜拜、爱过 提交于 2019-12-06 15:38:36
This is the SQL statement that I have. SELECT USER_PROFILE.FIRST_NAME, USER_PROFILE.LAST_NAME, USER_PROFILE.USER_TYPE FROM USER_PROFILE INNER JOIN USER_LOGIN_STATUS ON USER_PROFILE.USER_ID=USER_LOGIN_STATUS.USER_ID ORDER BY USER_PROFILE.FIRST_NAME And I'm trying to execute the code below that I thought the equivalent to hibernate DetachedCriteria and expected to only have two data as a result. DetachedCriteria dc = getDetachedCriteria(); DetachedCriteria userLoginCriteria = DetachedCriteria.forClass(UserLoginStatus.class); userLoginCriteria.setProjection(Projections.distinct(Projections

Join tables hibernate + group by

家住魔仙堡 提交于 2019-12-06 08:35:31
I need to do this query with Java + Hibernate. SELECT table2.id, COUNT(table2.id) AS count FROM table1 JOIN table2 ON table1.fk_tb2 = table2.id --many2one GROUP BY table2.id I would use DetachedCriteria class.....how can i do this ? Try using projections like this: Criteria table1Crit = session.createCriteria("table1"); Criteria table2Crit = table1Crit.createCriteria("table2", Criteria.INNER_JOIN); table2Crit.setProjection( Property.forName("id").count() ); storm_buster use your query with createNativeQuery method 来源: https://stackoverflow.com/questions/11146105/join-tables-hibernate-group-by

Can't get “count” and “groupBy” with Grails DetachedCriteria

依然范特西╮ 提交于 2019-12-06 00:55:08
I have a domain class that I use for querying . TourIndex{ Long tourId String country String location int availability // ... more fields } We use a series if "dynamic" criteria builders for searching based on a series of configurations that basically results in performing: def detachedCriteria = new DetachedCriteria(TourSearchIndex) detachedCriteria = detachedCriteria.build { eq('country','AR') } detachedCriteria = detachedCriteria.build { eq('location','salta') } I want to reutilize this logic and get the available filters with their respective results in the form [['location1', '3'], [