number « Query « JPA Q&A





1. Implementing result paging in hibernate (getting total number of rows)    stackoverflow.com

How do I implement paging in Hibernate? The Query objects has methods called setMaxResults and setFirstResult which are certainly helpful. But where can I get ...

2. Ordering by number of relationships in Hibernate    stackoverflow.com

I've got two models which have a one-to-many relationship. Lets say its an auction for a product and the product can have many bids. Basically what I'd like to do is pull ...

3. How do I select the nth element in a Collection by the number in an @IndexColumn?    stackoverflow.com

I have an ItemEntity class, which has a collection of ImageEntity's. I want to be able to fetch a specific ImageEntity, given its index in the collection. For example, ...

4. Counting the number of objects that meets a certain criteria    stackoverflow.com

The title doesn't tell the complete story. Please read the message. I have two objects: Adult and Child. Child has a boolean field isMale, and a reference to Adult. ...

5. hibernate - reduce the number of queries    stackoverflow.com

A Product can have 1 or more child Products forming a tree structure. Child Product's will also reference the parent Prdoduct. In my test code I've created 1 parent (mortgage) with ...

6. How can I limit the number of rows updated in a JPQL query?    stackoverflow.com

I want to limit this update query to only update 5 rows:

Query updateQuery = em.createQuery("update Entity e SET e.myVar = 1");
updateQuery.setMaxResults(5).executeUpdate();
setMaxResults does not seem to do the job. How can ...

7. How do I create a JPA query to return objects in descending order of the number of remote references?    stackoverflow.com

I have a @OneToMany relationship from Category.comparisons to Comparison.category (and a @ManyToOne relationship in the other direction). My Comparison object has a "date" field, and my Category object has a boolean "safe" ...

8. How do I count the number of rows returned by subquery?    stackoverflow.com

I want to do something like this:

select count(*) from (select ...)
(As it would be in SQL), but in JPA. Any ideas on how I would do it?

9. How to sort by number of votes in another table?    stackoverflow.com

In hibernate I have a table/class Question and a table/class Vote. Vote.questionId is a foreign key for Question.id. I want to sort the question by the number of votes. I am executing

session.createQuery("from Question ...





10. processing a large number of database entries with paging slows down with time    stackoverflow.com

I am trying to process millions of records from my table (size is about 30 GB) and I am currently doing it using paging (mysql 5.1.36). The query I use in ...

11. Hibernate Query column number mismatch    coderanch.com

Hi people, I encountered a strange problem while doing a supposedly simple Hibernate query. I defined 3 columns in the HQL, according to the Hibernate debug, the created SQL also contains 3 columns, but at calling query.list() Hibernate throws an exception saying that it is missing one column. Calling query.getReturnTypes revealed that the query expected a 4th column containing an integer. ...

12. find number of days in hql query    forum.hibernate.org

Hi! I use hql in named query. I'm interested to select records from the database between a birth_date and 30 days earlier. How do I do? In mysql birt_date column it's timestamp type. Ex "2009-12-31 12:01:33". Generally speaking, how can I find out the number of days between two dates by using HQL in named query?

13. SQLQuery IN Clause "ignores" large number of params    forum.hibernate.org

We are running a SQLQuery with large number of parameters like this: Code: String queryString = "SELECT FROM VIEW1, TABLE1...(several tables joined) where VIEW1.column1 IN (?....?)"; ...

14. Getting a wrong number of results from a native SQL query    forum.hibernate.org

Newbie Joined: Thu Dec 30, 2010 6:58 pm Posts: 5 I have a self-referencing table, let's call it FOO, with foo_id as PK. There is also FOO_LOG, where foo_id is a foreign key. It has all the same columns as FOO, plus an unmapped column named "__$operation", where only the following values occur: 1 for delete, 2 for insert, 3 for ...

15. Selecting the row number    forum.hibernate.org

Hello, Is there any way to select an absolute row number? This is a database feature required for searching when using pagination. A practical example would be an end-user searching for a name that starts with 'J'. The application wants to know on which pages the records with 'J' exists, so it can jump to the page and provide options like ...





20. Find out number of columns of a ScrollableResult    forum.hibernate.org

How do I get out the number of columns from a ScrollableResult ? When using the java.sql package, it can be done like this : //Assume results is of class java.sql.ResultSet //Assume rsmd id os class java.sql.ResultSetMetaData rsmd = results.getMetaData ( ); numCols = rsmd.getColumnCount ( ); How do I do the similar with Hibernate ? For the moment, I have ...

21. number of rows before real query    forum.hibernate.org

1) I'm sorry I keep on posting but I can't use the search on the forum... Is there a way to look for a string instead of a boolean expression? It's hard to look for "number of rows" using "number and rows"... 2) I have to divide a list of objects into "pages" of data. I'm using setMaxResults and setFirstResult, but ...

23. number of results in an Example query    forum.hibernate.org

24. Pagination: Number of results    forum.hibernate.org

25. Oracle, Pagination and number of pages (redux)    forum.hibernate.org

Hibernate version:2.1.8 I had posted a question about a way to translate HQL to SQL. Here's why I'd like to get the underlying SQL. Basically I need to display a paged table along with the total number of pages. Most of the pagination solutions for getting number of records from a Query object rely calling Code: scrollableResults.last(); scrollableResults.getRowNumber(); however as pointed ...

26. How can I count the number of query results without actually    forum.hibernate.org

How could you run that sql query without setting entity or scalar? >> org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before executing the query. [select count(*) from users] Your sql should probably look something like this: SELECT {person}.NAME AS {person.name}, {person}.AGE AS {person.age}, {person}.SEX AS {person.sex} FROM PERSON {person} WHERE {person}.NAME LIKE 'Hiber%' vgiguere's solution should definitely ...

27. Sorting varchar numbers using criteria    forum.hibernate.org

Hibernate version:3.0.5 Name and version of the database you are using:Oracle 9i Here is my situation, I have a varchar column which for the most part are numbers but could have text. I need to be able to sort this column and currently I am using Criteria.addOrder(...), however, of course, the numbers are being sorted as strings and are not in ...

28. Number of objects returned from a query    forum.hibernate.org

I have a query similar to: from Person p inner join fetch p.addresses where status='test' I'm using the Hibernate Console plugin for eclipse, which generates the sql. I copy the sql and run it on the database and the database returns back two rows. The only thing that is different b/w the two rows returned is address_id (primary key) and the ...

29. Selecting large number of objects by Id    forum.hibernate.org

Hi, I've got a lucene index which based on a search can yield me a large number of IDs. These IDs are for objects which I've persisted thru hibernate. (The search results are limited to a hundred rows or so). I then want to bring these objects back in thru Hibernate. The simple approach seems to be just having a large ...

30. Large number of selects taking long time to execute.    forum.hibernate.org

Hello, The scenario here is that I would have to query the database to select a row based on three conditions (conjunctions). And there are thousands (10,000 nearly) of such transactions. It takes a long time to execute these transactions. When doing a batch select(broader select with just one where condition) it takes less that a second to return, though a ...

31. query results in wrong number of rows    forum.hibernate.org

Newbie Joined: Wed May 04, 2005 9:34 am Posts: 16 Location: Germany Hi im using Hibernate with Spring and i have the following problem: I have a very simple database with one table. The corresponding domain-object mapped to the database with annotations looks like this Code: @Entity @Table(name="S_Benutzer", uniqueConstraints = {@UniqueConstraint(columnNames={"b_nr"})}) @org.hibernate.annotations.Table(appliesTo="S_Benutzer", indexes={@Index(name="b_nr", columnNames={"b_nr"})}) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @AccessType("property") ...

32. Reducing the number of selects from lucene query?    forum.hibernate.org

Hi, I am retrieving hibernate objects from a lucene query (using hibernate search). The query returns 5 objects, but the hibernate sql statements are dozens and dozens of selects. I thought the lucene search would retrieve the ID's and then select only for the number of lucene hits retrieved. Why do I have so many selects querying this way? thank you ...

33. Wrong number of rows with HQL distinct and maxResults    forum.hibernate.org

Hibernate version: 3.2.1 and 3.2.6 Oracle version: 10g with Oracle9Dialect. We seem to have found an error in the way Hibernate processes the combination of a distinct with a result limit in HQL. The HQL result will only contain 10 rows, but if you run the equivalent SQL query the result has the correct number of rows. Here is a reproduction, ...

35. how to use TO_NUMBER in ORDER-BY clause    forum.hibernate.org

36. Count number of references    forum.hibernate.org

I was trying to find the count of references to a specific entity. I've got the following model: - Client (the entity I want to count the references to) - ClientBased (a MappedSuperclass defining the reference to Client) - several entities extending ClientBased here's the JPA-query I've used: SELECT COUNT(all c) FROM foo.bar.ClientBased c WHERE c.client = ?1 HAVING COUNT(all c) ...

37. Counting number of nested objects managed by an entity    forum.hibernate.org

I have a Node entity that contains a set of children Nodes within it. A child node contains a set of children, and a child of it could contain more children. There is potentially an infinite level of nesting, but in practice that would not happen. What I want to do is count how many total children there are in the ...

38. User one session object for number of queries    forum.hibernate.org