criteria « Collection « JPA Q&A





1. Hibernate criteria/filtering - only return elements in collection that are specified in the criteria    stackoverflow.com

I have four hibernate classes: Trader, Legal, Party and Relation. Trader and Legal are types of party so extend it. A Trader can be related to a legal, a ...

2. How can I filter related collection with "and" condition (Hibernate Criteria API)    stackoverflow.com

Object Site has collection of objects Tag. Object Tag has property Title. How can I select all sites with tags 'A' and 'B' using Hibernate Criteria API?

3. Hibernate criteria filter inner collection    stackoverflow.com

I have the next classes/tables:

class User

  • id
  • name
  • works // list of work

class Work

  • id
  • name
  • user_id
So, Criteria criteria = session.createCriteria("User"); criteria.list() returns list of Users that contain list of Work object assotiated with them (by id=user_id) So, ...

4. Hibernate Criteria Collection of Objects    stackoverflow.com

I have a class with collection of Objects. Ex:

class XmlRequest{
            Long id;
         ...

5. Criteria and specific collection elements    forum.hibernate.org

6. Criteria and indexed collections    forum.hibernate.org

Hi everyone, I got a mapping like this: and I wish to perform a query with a restriction on a particular Position's index. I'm wondering if it's actually possible to do this using a Restriction or something that ...

8. Criteria and Collections    forum.hibernate.org

I trid with: Code: Criteria criteria=session.createCriteria(HUtente.class); HUtente hu=new HUtente(); hu.username="i%"; Example example=Example.create(hu); example.ignoreCase(); example.enableLike(); example.excludeZeroes(); criteria.add(example); criteria.createCriteria("gruppi","x0").add(Expression.eq("id",new Long(1))); criteria.createCriteria("gruppi""x1").add(Expression.eq("id",new Long(3))); List list=criteria.list(); But i get: java.sql.SQLException: General error, message from server: "Unknown table 'x0' in where clause" :( :( :( The sql is: Code: select this.id as id3_, this.cognome as cognome3_, this.descrizioneRuolo as descrizi3_3_, this.grado as grado3_, this.nome as nome3_, this.password ...

9. Criteria by Example, does it use collections...    forum.hibernate.org

Cat cat = new Cat(); cat.setSex('F'); cat.setColor(Color.BLACK); List results = session.createCriteria(Cat.class) .add( Example.create(cat) ) .list(); If cat.myCollection had some values in it, would those be used in the query? Or do you have to add an association criteria like so: Cat cat = new Cat(); cat.setSex('F'); cat.setColor(Color.BLACK); List results = session.createCriteria(Cat.class) .add( Example.create(cat) ) .createCriteria("kittens") .add( Expression.like("name", "F%") .list(); ?





10. criteria across collections and OR    forum.hibernate.org

I tried that, it's not quite what I'm looking for. The expression you gave is the equivalent of an AND. It returns records where the company name matches AND either the first or last name match. I'm looking for a 3 way OR. Either the first name OR the last name OR the company name could match. The idea is that ...

11. Differenct sub-criterias on the same collection    forum.hibernate.org

SELECT Person FROM Person As Pers WHERE Pers.Id in (SELECT PersonId FROM Address as Adr WHERE Adr.City = 'Moscow' AND Adr.Type = 1) AND Pers.Id in (SELECT PersonId FROM Address as ...

12. Is it possible to filter a collection within a criteria?    forum.hibernate.org

I have a parent/child relationship where I want to use a criteria query to find results based on attributes within the children. Then I want to return the matching parents with their children filtered to only the matching children. Is this possible? So let's say the child class that has an attribute of hairColor. I want to search for parent objects ...

13. Using Criteria.addOrder() with collections?    forum.hibernate.org

I develop an admissions decision suppport system for use by tutors at a university with a collegiate system. Applicants ("candidates") specify a preferential order of colleges at which they wish to take their course, although it is not necessary to specify second or higher college preferences. Tutors are affiliated with colleges, and are often interested to see a list of all ...

14. Criteria and collections of elements    forum.hibernate.org

I have a class ContractRequest that contains a map of , mapped like so: Code: /** * @hibernate.map table="icd.tblcontractrequestfield" * @hibernate.collection-key column="cnrq_id" * @hibernate.collection-element column="cnrf_value" type="string" * @hibernate.collection-index column="cnrf_key" type="string" * @return ...

15. Writing Criteria for Conjunction in a collection    forum.hibernate.org

16. Criteria and filtered collections - inconsistent behavior?    forum.hibernate.org

Hi, I have two tables: OWNER (ownerId, name) and CAR (carId,ownerId,color,make,model). Owner class looks like this: Owner{ownerId,name,cars}. Car class looks like this: Car{carId,owner,color,make,model}. As you can see, Car object has many-to-one relationship with Owner. I create Criteria object like this: Criteria c=session.createCriteria(Owner.class); c.add(Expression.eq("name","John")); And I add a filter on Car collection (name="colorFilter", param="color", condition="color=:color") like this: session.enableFilter("colorFilter").setParameter("color","red"); As of now I ...





17. "Extra lazy" Collection with Criteria    forum.hibernate.org

Thanks. I was just thinking perhaps there was a way to make list() behave just like an extra lazy collection. That way you would be able to use subList(..) and size() for pagination. :) I'm on mysql now so I'm not sure ScrollableResult is a good idea. I'll just stick to setFirstResult/setMaxResults for now.

18. Criteria API and Collections    forum.hibernate.org

Ok, I've spent a few hours searching forums, documentation, FAQ... and I am no closer to solving my problem. Simple scenario: @Entity class Customer { @OneToMany List pets; } @Entity class Pet { Breed breed; String name; } I'd like to use the Criteria API to search for Customers with pets that either match a given breed or a given name. ...

19. Using Criteria API to recreate any elements(collection)    forum.hibernate.org

I have been searching for 2 days to try to find this. Hopefully it is simple and I have just overlooked something. I have an object (Contact) with a Set element and I would like to use the Criteria API to limit search results to those results that have one of the elements of that Set in another Set. I will ...

20. Hibernate criteria with parameters collections    forum.hibernate.org

21. Help with Criteria API and collections needed please    forum.hibernate.org

Say I have the following classes: class Cat { List kittens; } class Kitten { String name; } How, using the Criteria API can I query for a list of Cats who DO NOT have a kitten with the particular name "Moggy". The closest I can think of is the following, although I think it returns a list of cats that ...

22. criteria and collections    forum.hibernate.org

Hi, I think you can try using Distinct clause. In criteria API you filter the retrieved list using import org.hibernate.transform.DistinctRootEntityResultTransformer; return new DistinctRootEntityResultTransformer().transformList(list); where list is the results u have got after executing Criteria. Important thing is doing distinct this way is totally different from having Distinct in select clause as SQL or HQL level, as here first you get the ...