criteria

JPA Criteria API missing

你说的曾经没有我的故事 提交于 2019-12-12 18:08:25
问题 I'm building application that uses JPA, and I want to use Criteria API as described http://openjpa.apache.org/builds/latest/docs/manual/jpa_overview_criteria.html. More precisely this part: EntityManager em = ... ; CriteriaBuilder queryBuilder = em.getCriteriaBuilder(); CriteriaQuery qdef = queryBuilder.createCriteriaQuery(); The problem is that there is no getCriteriaBuilder() method in my EntityManager and also CriteriaBuilder and CriteriaQuery cannot be found in the persistance-api-1.0.jar

Hibernate criteria query

早过忘川 提交于 2019-12-12 17:39:02
问题 I am trying to execute a subquery using Hibernate criteria api but not been able to figure out completely how to go about it. Assuming there are 2 tables, SHOPS and EMPLOYEES, where SHOPS has all the shops information and EMPLOYEES is a big table of all the employess in all the shops (No foreign keys set). I am trying to write a query, which retrieves the shop id and address from the SHOPS table and then retrieves the number of employess in a shop by a join and count on EMPLOYEES table.

Using NHibernate Criteria to sum across multiple properties/columns

别说谁变了你拦得住时间么 提交于 2019-12-12 13:11:27
问题 Does anyone know how to express the following SQL statement using NHibernate criteria? SELECT SUM(Val1 + Val2) FROM SomeTable Seems simple, but AFAIK I can't seem to find a way to do this without returning an array of values, the sums of Val1 + Val2 seperately and then summing from the array, which I want to avoid. 回答1: In comments to blog post that @Jaguar has mentioned in his answer NHibernate and the missing OperatorProjection is an alternative solution: session.CreateCriteria()

NHibernate Criteria select items by the group by and sum of itemid within another table

夙愿已清 提交于 2019-12-12 12:16:53
问题 public class SearchText { public virtual int Id { get; set; } public virtual string Text { get; set; } } public class SearchTextLog { public virtual int Id { get; set; } public virtual SearchText SearchText { get; set; } public virtual User User { get; set; } public virtual int SearchCount { get; set; } public virtual DateTime LastSearchDate { get; set; } } I am trying to select the top 5 SearchText items based on the sum of their count within the SearchTextLog. Currently I have only been

Java, Hibernate java.lang.ClassCastException: org.hibernate.collection.PersistentSet cannot be cast to java.util.HashSet

放肆的年华 提交于 2019-12-12 10:56:22
问题 I have two tables, DVD and Contact. A DVD can be rented to a contact and a contact can rent many DVD's. The many to one link (dvd-->contact) works fine. But the other way fails: (contact-->dvd) This is the contact mapping: <set name="dvds" inverse="true"> <key column="contactId"/> <one-to-many class="Dvd"/> </set> Here is setter getter for Contact: private Set<Dvd> dvds = new HashSet<Dvd>(); public Set<Dvd> getDvds(){ return dvds; } public void setDvds(Set<Dvd> dvds){ this.dvds=dvds; } When I

Hibernate Child Collection Limited When Using Left Join in Criteria

核能气质少年 提交于 2019-12-12 08:56:14
问题 When using hibernate criteria just altering the join type affects the results of the child collections of the root domain class. For instance, having class Parent have a one-to-many relationship with class Child with the following data: Parent | id | Name | | 1 | Parent 1 | Child | id | parent_id | Name | | 1 | 1 | Child1 | | 2 | 1 | Child2 | Using the following hibernate criteria returns the 1 parent row, and accessing the child collection results in the two rows being returned: session

Hibernate Criteria: Left Outer Join with restrictions on both tables

醉酒当歌 提交于 2019-12-12 07:26:24
问题 I am doing a LEFT OUTER JOIN, but I am only able to apply Restrictions on the first table. Is there a way ti apply on the second table as well? Here is my code: Criteria criteria = this.crudService .initializeCriteria(Applicant.class).setFetchMode("products", FetchMode.JOIN);. This works (applicant has an applicantName property): criteria.add(Restrictions.eq("applicantName", "Markos") Neither of these works (product has a productName property) criteria.add(Restrictions.eq("productName",

nhibernate criteria - table name has double quotes

穿精又带淫゛_ 提交于 2019-12-12 06:17:20
问题 I am using Fluent NHibernate in my application. I have a criteria query that looks like this - var query = DetachedCriteria .For<table2>() .SetProjection(Projections.Distinct(Projections.Property("id"))) //.Add(Restrictions.Between("date_field", startDate, endDate)) .Add(Restrictions.Eq("id", 204010)); Add(Subqueries.In("id", query)); This errors out with the error - NHibernate.ADOException was unhandled Message=could not execute query I looked at the query and tried to run it, but it also

Hibernate criteria, distinct association property

老子叫甜甜 提交于 2019-12-12 05:59:57
问题 Say I have at least these two entities: class Person { String firstname, lastname; Address address; ManyOtherPropertiesAndEntities ...; } class Address { String street; Country country; } Now, I would like to query the Person table and ONLY Persons that live on different streets. That is, ignore all Persons that live on same street , and return only one of these Person, any one. How can I perform such a query? Is that possibly using Criteria ? Criteria criteria = session.createCriteria(Person

A correct way to load entities by Id list when Id is not mapped

不问归期 提交于 2019-12-12 05:39:40
问题 I have the following code string idName = builder.IdentifierName; Disjunction disjunction = Restrictions.Disjunction(); IList ids = new ArrayList(entityInfos.Length); foreach (var entityInfo in entityInfos) { ids.Add(entityInfo .Id); } disjunction.Add(Restrictions.In(idName, ids)); criteria.Add(disjunction); criteria.List(); (I haven't written it, it's simplified code from NHibernate.Search) Value of idName is correct ( "Id" ). In my mapping I do not have Id mapped to an entity property, it