Record « Query « JPA Q&A





1. How to order records by a computed column in Criteria API?    stackoverflow.com

How can I write the below HQL query using the Criteria API?

select s.Name, sum(q.PointsObtained), sum(q.TotalPoints)
from Student s join s.Quizzes q
group by s.Name
order by (sum(q.PointsObtained) / sum(q.TotalPoints)) desc

2. Handle ordering of different records in different tables using Hibernate    stackoverflow.com

Lets say that I have a database with the following tables:

CREATE TABLE user (
   user_id int NOT NULL AUTO_INCREMENT,
   ...
   PRIMARY KEY (user_id)
);
CREATE TABLE action_x ...

3. Find Next and Previous record using hibernate    stackoverflow.com

what is the best way to find next and previous record using hibernate (criteria possibly). I'm using a query based on ordering and LIMIT 1, but i think it's too slow on ...

4. JPA query, find values for chosen members of groups of records    stackoverflow.com

Suppose I have a table with some natural grouping and ordering, for example records by date, where the records for any given date are ordered by some other differentiator field

  ...

5. HQL sorting records by using greatest of 2 columns    stackoverflow.com

For each row in my database, I have 2 columns, say id and A. Sometimes A can be null. I want to sort all records by greatest of its id ...

6. Using HQL with MySQL how can I order the result set before the group by so the right record is picked?    stackoverflow.com

Is there any way to write a greatest-n-per-group query in HQL (or potentially with Hibernate Criteria) in a single query? I'm struggling with a problem that's similar to this: Schema:

  • Book has a publication_date
  • Book ...

7. How to select last inserted record from Table Using HQl    coderanch.com

HI All, I am Beginner to Hibernate,I have a problem. Usually after inserted a new record in Table , I want to select the same record from table Using HQL. Prestetly i am implementing this as following method. for example. Table Employee cols: empno empname 1001 Suresh 1004 Magesh Here empno is Auto generated. I don't know what is the no ...

8. hql query to get records of the week    coderanch.com

9. Selecting the last record in the table using Hibernate    coderanch.com

Can anyone please tell me with an example, how to retrieve the last row in the table. I am using MySQL and Hibernate I have tried with max(rowid), order by desc limit 1. But it doesn't work. I am getting an error,"could not execute Query" You have an error in your SQL syntax; check the manual that corresponds to your MySQL ...





10. Hibernate query returning 0 records    coderanch.com

I have an application that uses hibernate to get data from a MySQL database. I've enabled hibernate logging, and can see the query that is being generated. When I copy that query into the MySQL Query Browser and plug in the same values as are passed to my code, I get a bunch of records (867); when the code runs, however, ...

11. delete query in hibernate giving error as null, and not deleting the record    coderanch.com

Hi, below is my FirstExample.java file and Contact.hbm.xml file when run FirstExample.java it is giving error as null, and not deleting the record FirstExample.java file import java.sql.Date; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.Query; import utils.Insurence; public class FirstExample { public static void main(String[] args) { Session session = null; try{ SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession(); String hql ...

14. Not getting latest records using session.createSQLQuery()...    forum.hibernate.org

My problem is -- 1. I have a button "View List" on a JSP by clicking it I am displaying records in a select box.Data is coming from let say Table1. 2. I am inserting records into same Table1. 3. Now again If I click on "View List" this time newly inserted record is not coming in the. My code details ...

16. To find Total Records Count for the parent table    forum.hibernate.org





18. how to select only one record from db    forum.hibernate.org

hi, i want fetch only one record from database irrespective of id. please can u tell me the solution. if use Query then i will always gives my persistence objects in the form of lists, so, i dont want it. example: -------- Person person=(Person)session.get(Person.class, id); above statement returns only one row, similarly ,i want to fetch only one record from database ...

19. How to find a particular record out of 1000records using hql    forum.hibernate.org

Hi to all , i am new to hibernate , i am tring to retrive data from database using hql , the code which i used is--- i am getting the records, but help me to ger a better one Thanks for support.. Session s=null; try { SessionFactory sf=new Configuration().configure().buildSessionFactory(); s=sf.openSession(); String sql="from FacultyCourses"; Query q=s.createQuery(sql); for(Iterator it=q.iterate();it.hasNext();) { FacultyCourses obj=(FacultyCourses) ...

20. Sometimes query returns only one record    forum.hibernate.org

21. How to query selected Months records    forum.hibernate.org

22. query on many to many table gives duplicate records.    forum.hibernate.org

Newbie Joined: Fri Apr 29, 2011 5:24 pm Posts: 3 hi selecting on many to many relation is giving duplicate records of first table. it is tough to ask this in simple one line, so i am giving example here. i have 2 tables candidate and job with following many to many relation. candidate candidateSeq(PK) firstName lastName Job jobSeq(PK) jobTitle candidateJob ...

23. find out offending record on ConstraionViolationException    forum.hibernate.org

Greetings. Maybe I'm missing something but I'm really surprised that Hibernate is not reporting a constraint violation on insert, only when I call commit. At that point I may have inserted a number of records and I have no idea what the offending one was. Thoughts? Details: Java 6, Hibernate Core 3.3.1 GA. Related code snippets: Session session = sessionFactory.getCurrentSession(); tx ...

24. How to get record count?    forum.hibernate.org

My Criteria has complex query condition. If I use hql to count total result num that fits those complex query condition, shall I compose those condition with hql again? That means I would compose those query condition with two ways:hql and criteria. One for count and one for query. If it is true I have no reason to use criteria. Criteria ...

25. "read all records" and session.find on this collec    forum.hibernate.org

Hello! Maybe i am blind, but i just cant find something which helps me. Is it possible to read all records in an table into a map where the key is other than the pk-key of the table? Much like the in an hbm.xml but i do not have a parent-child association. The table is simply the "root"-Table. Since ...

26. Counting records with Criteria object    forum.hibernate.org

27. How to delete a record like trigger?    forum.hibernate.org

Senior Joined: Wed Dec 17, 2003 4:24 am Posts: 188 Hi everyone: I have two tables A and B. They don't have any associate. But I want to delete one record from A and update one record from B in the same time. I see the hibernate docs , this code seems can do it: Code: public class AuditInterceptor implements Interceptor, ...

28. Get Records in Descending order.    forum.hibernate.org

29. inserting records using named queries    forum.hibernate.org

hi , thanks for the reply , but actaully i have to insert not thru the save or update.... as i have insert manually using named queries or HQL or something else........ as insert in to DB it ll generate a number and assiign for that record .. thats my crit... so please help me in out in writing queriy to ...

30. hib query returns null when the record IS in db    forum.hibernate.org

hib query returns null when the record IS in db: Mapping document:

31. Why the returned query results contain the same record?    forum.hibernate.org

I am a new user and playing Hibernate 2.1.8. Everything seems OK except I got a strange returned query results. In order to get my first Hibernate code worked, I use a simple query statement something like Criteria crt = HibernateUtil.getSession().createCriteria( Message.class); crt.add(Expression.between("postedDate", start, end)); crt.add(Expression.eq("author", author)); crt.addOrder(Order.asc("postedDate")); Collection c = crt.list(); logger.debug("# of records:" + c.size()); When I run my ...

32. How to select an inserted record???    forum.hibernate.org

33. Query by Example finds all records    forum.hibernate.org

I am trying to use the query by example approach provided for within Hibernate. And it works ... sort of ... No matter what I put in the example object, the query returns all records from the database (as objects, of course). Clearly, I am doing something wrong. Here is my code, including the documentation that tells you what it is ...

34. Problem Selecting Records from a View(?)    forum.hibernate.org

Hi, Bit of a newbie here and I'm sure this question must have been answered before, but I couldn't find it anywhere in the Forum or FAQ. Anyway, my problem relates to performing a simple Select. The line of code in question is as follows: List result = session .createSQLQuery(sql) .addEntity("tableRef", getDataClass()) .list(); 'sql' above is simply a String which resolves ...

35. subquery with a peculiar twist - paging records    forum.hibernate.org

using the view V$SQLTEXT i have verified that hibernate retrieves only bvalues which are concerned with the page. example query obtained from the server view : select * from ( select row_.*, rownum rownum_ from ( select hsor derhis0_.order_history_id as order1_51_0_, trader1_.trader_id as trader1_50_1_, hsorderhis0_.base_order_id as base2_51_0_, hsord erhis0_.trader_id as trader3_51_0_, hsorderhis0_.specie_id as sp ecie4_51_0_, hsorderhis0_.position_account_id as position5_51_0_ , hsorderhis0_.actual_display_name as ...

36. Record count with named query    forum.hibernate.org

Hello, Is there an easy way of counting records that where selected in a named query, before i get the results in a collection?? I want to count the number of records before I apply my paging, using setFirstResult setMaxResults I know that I can do it with criteria, buy using criteria.setProjection(Projections.rowCount()); thank you

37. query does not return records with null values    forum.hibernate.org

Query query = session .createQuery("SELECT new Player(p.id, state, p.name, p.profileUrl, " + "p.photoUrl, p.type, p.playerClub, p.dateOfBirth) " + "FROM Player as p JOIN p.states as state " + "WHERE state.round.id = :roundId AND state.club.id = :clubId AND p.type.id = :typeId " + "ORDER BY p.name ...

38. How to sort Detail Table records    forum.hibernate.org

Hi, I am pretty new to Hibernate and needs some help in resolving the following issue. I am trying to retrieve Menu and SubMenus data from Database tables. I have two tables Hiber_PARENT_MENU and Hiber_CHILD_MENU. How can I keep the order of my detail records i.e. Sub Menus .Right now everytime I refresh the page Sub Menus order keeps changing. Following ...

39. Criteria get total record count    forum.hibernate.org

I'm using Criteria for a report with lots of filters, and page flipping. For the page flipping I'm using the: criteria.setMaxResults(); criteria.setFirstResult(); I would like to be able to display the total records for the user, however this list will just have the 25 because I'm only doing 25 per page. Is there somehow to count the total records? something like: ...

40. Hibernate Cache not pulling new records after a refresh    forum.hibernate.org

Hibernate version 3.1, XML Mapping, jdk 1.5 My application is a read only data pull and the data is update elsewhere outside of Hibernate. However I need to have Hibernate pull the new record when it is added to the table. I clear the session before the refresh and that will bring back updated records. But new records are not returned. ...

41. Hibernate Query skips records    forum.hibernate.org

If your posting (or a question you are referring to) was not answered by anybody, the possible reasons are: - http://www.hibernate.org/ForumMailingli ... AskForHelp - You did not submit enough information - Nobody knows the answer or has the free time to answer What you can do now: - Do the things listed in After Posting - Add missing and/or more information ...

42. Criteria + record count of Subquery    forum.hibernate.org

I would like to get the record count of subquery by the following SQL: Code: select count(*) as total from ( select pf.source, ...

43. Hibernate query not returning records    forum.hibernate.org

Hi i need to pick up some flights (airlines) which has taken off between 11th aprill 2007 12 oclock noon and 12th april 2007 12oclock noon.i have written a hivernate query whcih is not returning any records,when i am taking up the same query generated from hibernate and run it on toad it is returning record against perticular flight no. the ...

44. Paging records using hibernate    forum.hibernate.org

46. find by example does not return me exacts records    forum.hibernate.org

Hi all I have a function that uses Example API with MacthMode.EXACT. The problem is that when i passed it an object with just its id specified, the functions return me all records starting with that id. I need an EXACT search matchmode.I already specified it in MatchMode.EXACT but the problem is not solved. My function : public Collection findByExample(Object example) ...

47. Hibernate deleting records on query?    forum.hibernate.org

Hello all, I have recently stumbled upon a a fairly nasty issue with Hibernate used in a concurrent environment. I have one entity class that references a collection of composite objects. This is the relationship defined in Xdoclet markup: * @hibernate.set table="CUSTOM_VALUES" lazy="false" cascade="all" * @hibernate.collection-key column="VALUE_ID" * @hibernate.collection-composite-element class="com.test.Value" * @hibernate.collection-many-to-one column="FK_VALUE_ID" * class="com.test.MainEntity" * not-null="true" I am able to ...

48. Hibernate 2 Queries are not retrieving all of the records    forum.hibernate.org

I have inherited a legacy system which uses Hibernate 2. I have a problem where it's not retrieving all the records which exist in the database table. It should retrieve 8 records but only retrieves 5. The developers that left obviously did not test the system before rolling it out. :-( I would like to know how I can investigate why ...

49. do counting records for table    forum.hibernate.org

I use method below to do counting of total records in table. I realized there is a slow down when my records in mysql datbase grew. I only need counting no need to assign each record to my Emaillist.class object. I suspend this is not the right way to do counting. What is the best way to do counting? Criteria crit ...

50. After delete record, select all records are wrong    forum.hibernate.org

Author Message bmili Post subject: After delete record, select all records are wrong Posted: Mon Jan 21, 2008 3:34 pm Newbie Joined: Sun Jan 20, 2008 3:05 pm Posts: 1 After selected record is deleted, remaining records are displayed correctly. When all records are selected again, they are as before delete Deleted record is displayed. Need help with Hibernate? ...

51. Query retrieving duplicate records    forum.hibernate.org

Author Message davout_uk Post subject: Query retrieving duplicate records Posted: Thu Jan 31, 2008 5:02 am Regular Joined: Tue Apr 10, 2007 10:02 am Posts: 50 I'm using Hibernate as the DAO within a Spring business tier. For one 'findQuery' call the resultant list contains 3 times the number of records that actually exist, i.e. there are 7 records, ...

52. Does maxNodes/LRUPolicy affect queries? I'm losing records.    forum.hibernate.org

Hibernate version: 3.2.3 ga JBossCache version: 1.4.1SP8 Hi all! In a clustered environment where the second level cache is JBossCache, Im using LRUPolicy. Ive set maxNodes at 5000 for a particular region that represents a Hibernate object. I believe this is working because Im using Hibernates built-in cache stats reporting and the number of entities persisted for the region gets close ...

53. How to return only like 20 records?    forum.hibernate.org

public class FindFirstFive { public static void main(String args[]) { User user = new User(); Session session = HibernateUtil.beginTransaction(); Criteria criteria = session.createCriteria(User.class); criteria.setFirstResult(0); criteria.setMaxResults(5); List results = criteria.list(); HibernateUtil.commitTransaction(); for (int i = 0; i

54. HQL or Criteria? finding average and most distinct record    forum.hibernate.org

I am using a spring / hibernate 3 stack. I have 2 issues.... but they are somewhat related so I decided to throw them into 1 post: Background: I have the following table (or something similar) GROUP_ID - PK EFFECTIVE_DATE - PK UPDATE_DATE -PK TYPE - PK AMOUNT As you can see, it is a table with a composite key. I ...

55. HQL Query to get 10 records    forum.hibernate.org

56. HQL Query to get 10 records    forum.hibernate.org

57. Get the sort record by using hibernate query.    forum.hibernate.org

58. Delete and Insert records from joining table while selecting    forum.hibernate.org

Hi, I am using Hibernate version:3.2 I have a many to many relationship between two tables Category and Item for which i used a joining table Category_Item.The joining table is having an additional column createdUser apart from the primary keys of the parent tables. The problem i am getting here is while fetching the data from Category table insert and delete ...