Restriction « Query « JPA Q&A





1. Can you order hql results based on matching restrictions?    stackoverflow.com

I have an object Dog which holds a set of DogMetadata. Each DogMetadata has two values: a String ("desc") and an int ("rank"). Descriptions of dogs have different rankings such as: "small" is ...

2. hibernate restrictions and/or order    stackoverflow.com

small questions about Restrictions.or and Restrictions.and If I do something like this:

...
criterion = criterionA;
criterion = Restrictions.and(criterion, criterionB);
criterion = Restrictions.or(criterion, criterionC);
criterion = Restrictions.and(criterion, criterionD);
Will this be treated as:
(A and B) or (C and ...

3. Is there something like Restrictions.eq(true, false) in Criteria API?    stackoverflow.com

I need a generic Criterion which forces the result to zero matches. Something like Restrictions.eq(true, false) ?

4. Hibernate Criteria and row count restriction    stackoverflow.com

i have two entities named Parent and Child, linked in a one-to-many relationship. The Child entity has a boolean isStudent property. How do i get, using the Hibernate Criteria API, all ...

5. Hibernate Criteria Projection    stackoverflow.com

Well as the question says, i am trying to make a projection criteria querying only couple of the table attributes. So I have a Person Table/class and it has about 40 attributes ...

6. Combining Restrictions and Projections on DetachedCriteria    stackoverflow.com

I have problem with combining Restrictions and Projections on DetachedCriteria. If I use only Restriction or Projections separately the program works. How can I combine those two together? I have following ...

7. Writing a Hibernate Criteria API Query with restrictions for multiple sub-elements    stackoverflow.com

I have a data model that looks like this (simplified example):

public class Address { private List<AddressLine> addressLines; }

public class AddressLine { private String value; private String type; }
I am trying to ...

8. Hibernate exception 'could not resolve property' when doing a query with Criteria and Restrictions    stackoverflow.com

I have a OneToMany relation in hibernate defined like this:

@Entity
@Table(name = "groups")
public class Group extends BaseModel {// BaseModel defines id as @Id and @GeneratedValue

    @OneToMany
    ...

9. select id if more than twenty columns satisfying conditions    stackoverflow.com

Ideally i need the query in Hibernate Criteria API, but it will be very helpful even in Native-SQL. I have a table with columns id, a1, a2, a3, a4, a5, ... ...





10. Hibernate Criteria query conundrum    stackoverflow.com

I've got a schema with a series of OneToMany associations, where the hierarchy is Farm -> Field -> RegionGroup -> Region and need to be able to query based upon values ...

11. Hibernate query table size restrictions    forum.hibernate.org

All, I am using hibernate 3.2.6ga with annotations 3.3.1. I have been using hibernate for about 3 years and have not had any problems until now. I have a db that i can access and perform CRUD operations on with about 15 tables. But one has 500000+ rows in it and when i perform a query against it i get back ...

12. Restrictions.isEmpty() ignores where clause    forum.hibernate.org

13. JPA2.0 Criteria API: count(*) / select * from 1 restriction    forum.hibernate.org

// Set up criteria (restrictions) CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery criteriaQuery = builder.createQuery(EntityStub.class); Root entity_ = criteriaQuery.from(EntityStub.class); criteriaQuery.where(builder.equal(entity_.get("message"), "second")); // Generic retrieve list (Works) TypedQuery entityQuery = entityManager.createQuery(criteriaQuery); List entities = entityQuery.getResultList(); // Generic retrieve count (doesn't work) CriteriaQuery countQuery = builder.createQuery(Long.class); Root entity_ = countQuery.from(criteriaQuery.getResultType()); countQuery.select(builder.count(entity_)); Predicate restriction = criteriaQuery.getRestriction(); if (restriction != null) { countQuery.where(restriction); // Copy ...

14. Using a Restriction.like criteria on a numeric property    forum.hibernate.org

I've never done this with hibernate, just an idea.... can you use an expression in the restriction? Simply take the modulus of the numeric field against the search string length and compare the values (both numeric). [Edit it should read 10^(power of the search string length), read between the lines =P, same goes for later] This will find if the string ...

15. Adding restrictions on a JOIN-query    forum.hibernate.org

16. sorting/restrictions on dependencies    forum.hibernate.org





18. DetachedCriteria adding Restrictions and Projections    forum.hibernate.org

Hi, I have problem with combining Restrictions and Projections on DetachedCriteria. If I use Restriction or Projections separately the program works fine. How can I combine those two together? Here is my sql: "select cTopic.topic ,SUM(cTopic.records) as records from Topics cTopic where cTopic.id=? and cTopic.active =? GROUP BY cTopic.topic order by cTopic.orderTopics The following Java codes work fine without using group ...

19. Criteria Query: Restrictions and Collections    forum.hibernate.org

yeah that's what i first tried..... criteria = session createCriteria(LabeledItem.class) .createCriteria("labels"); for (Label label : allLabels2match) { criteria = criteria.add(Restriction.eq("name",label.getName()); } but that doesn't work as it is equivalent to this SQL: select id_item from labeleditems li , label l where li.id_item = l.iditem AND l.name = 'name1' AND l.name = 'name2' AND l.name = 'name3' ................. AND l.name = 'namen' ...

20. Variable number of Restriction.or() clauses    forum.hibernate.org

Newbie Joined: Mon Nov 20, 2006 5:28 pm Posts: 4 Suppose I have a simple table named "Book" with a column named "Title" VARCHAR(500). [Books] ------------------------------------------------ |id | title | ------------------------------------------------ | 1 | "Gone with the Wind" | | 2 | "The Stand" | | 3 | "Standing at the edge" | | 4 | "Standing at the edge of ...

21. Restrictions to join part of the query?    forum.hibernate.org

Edit: I solved the problem describe below using HQL and currently I am looking for answers to these questions: 1. Is there any way, how to apply extra join conditions using Criteria API? (The "with" keyword in HQL) 2. Is there any way, how to specify join order using parentheses in HQL / Criteria API?

22. Applying Criteria restrictions to Native query. My solution    forum.hibernate.org

I'm using native query API. But it is usual to apply dynamic filters, ordering and limiting first and maxResults of a query. Criteria interface is ideal for that. I have written small utility class to apply critetia query restrictions to native query. Here is usage code sample CriteriaParams critPar = new CriteriaParams(); critPar.add(Restrictions.eq("P.FULLNAME", "Doe")); critPar.addOrder(Order.asc("P.SHORTNAME")); CriteriaSQL csql = new CriteriaSQL(critPar); SQLQuery ...

23. Can you append a restriction to a query dynamically?    forum.hibernate.org

Hibernate version: 3.2.0 Hi Guys Is it possible to configure an interceptor ( or something similar ) to append a where clause to all dynamically generated queries? I have a flag in every table which I need to add to the clause, but I don't want it to live in the object model at all. ie when calling the load method ...

25. using Restriction and Projection classes    forum.hibernate.org

Dear Sirs The hql query below work fine: String query = "select t from TextVersion as t where version = " + "(select max(version) from TextVersion where headline_id = " + headlineId + ") and headline_id=" + headlineId; List textVersions = hibernateSupport.findByHQL(query); the POJO class is TextVersion and I am able to retrieve objects from this class in List textVersions. I ...

26. DetachedCriteria Group By with Count restriction - possible?    forum.hibernate.org

I am facing a problem where I am trying to do a group by and count unique and display only those records where the count is at least some number. I was able to successfuly write some HSQL below that will return me the count and an instance, but I want to further reduce the resultset by saying that I only ...

27. Pagination with key restriction to know which page to show.    forum.hibernate.org

I understand how basic pagination works, and have been successful at using it in Hibernate with the setMaxResults and setFirstResult api on the criteria object. However, now I have the a problem where the user wants to display the page of results that contains a particular key of information. For instance, if there are 10000 total rows with 10 rows per ...

28. Query cache invalidation with natural-id restrictions    forum.hibernate.org

Newbie Joined: Thu Mar 20, 2008 5:27 pm Posts: 1 I am migrating a legacy system that performs a number of repetitive queries by immutable composite business keys. While I am using surrogate keys in the migrated database, to boost performance, I setup natural id mapping, a query cache and second level cache as described in the hibernate documentation, section 15.9, ...

30. Problem with German Umlauts and Restriction.like    forum.hibernate.org

31. invalid sql when using projection and restriction    forum.hibernate.org

Criteria criteria = getActorDao().createCriteria(); criteria.add(Restrictions.or( Restrictions.ilike("name", "adi"), Restrictions.ilike("description", "adi") )); criteria.setProjection(Projections.projectionList() .add(Projections.groupProperty("name"), "name") .add(Projections.groupProperty("description"), "description") ); criteria.setResultTransformer(new AliasToBeanResultTransformer(ActorTestDTO.class)); List ...

32. Need help on Criteria Query Restrictions.    forum.hibernate.org

33. Can you order hql results based on matching restrictions?    forum.hibernate.org

I have an object Dog which holds a set of DogMetadata. Each DogMetadata has two values: a String ("desc") and an int ("rank"). Descriptions of dogs have different rankings such as: "small" is 5, "furry" is 2, "friendly" is 9, "dalmation" is 11, "mutt" is 22. I need to search for dogs based on any of their desc values (for example, ...

34. Polymahic Restriction Query question    forum.hibernate.org