return « Query « JPA Q&A





1. Return a column in hql select clause without actually using that column    stackoverflow.com

I have a query which returns a list of objects like such:

select distinct ref from references where [...]
I'd like to order these by a field not on ref but on an ...

2. nhibernate query to return a User by his Guid    stackoverflow.com

I have a user class:

public class User
{
   public virtual int ID {get;set;}
   public virtual string UserGuid {get;set;}  // its unique!
}
Can someone show me how to query ...

3. How to get a distinct result, but return another column in the select?    stackoverflow.com

I want to get a distinct result based on a property, but return the id in the select because I will be using it in a subquery. e.g.

(List<Article>) session.createQuery("from Article a where ...

4. Hibernate query not returning full object    stackoverflow.com

I have a list of items. Each item has set of categories. I want to grab all the items of a specific category. This part is simple. The part I am ...

5. Hibernate HQL: Get count of results without actually returning them    stackoverflow.com

I want to get the count of the results of a dynamically-generated HQL query, without actually getting the list of results. Say that the query I have is something like:

select Company ...

6. unexpected sublist result returned by Hibernate query    stackoverflow.com

I hava a HQL query as the following which returns a java.util.RandomAccessSubList of ORDER. The offset of the SubList is 1,so the first element of the query result list can't be ...

7. JPA 2 Query Returning Incomplete Results    stackoverflow.com

The following query is only matching the first value found in the select subquery, even though there are match for all values SELECT p FROM Profile p WHERE p.id IN (SELECT ...

8. Hibernate getting only column1 from a query returning multiple columns    stackoverflow.com

I have a query of this nature

String query = select column1, group by column2 from table1 ...
//What should I write to just get column1 from the query.    ...

9. Hibernate query returning error    stackoverflow.com

I have the following hibernate query -

    events = (List<Event>)session.createQuery(
            "Event where eventName like " 
 ...





10. Using hibernate return count value of a query    stackoverflow.com

this is my mysql query:

SELECT count(*) 
FROM bw_jobs 
WHERE year(job_date)=year(curdate()) AND month(job_date)=month(curdate());
How to use this in hibernate to get count value?

11. How to properly determine whether an "exists" JPA Criteria Query clause returned true or false?    stackoverflow.com

I don't know how to make JAP criteria query end up with a boolean output. The goal is to have a criteria query that looks like this when rendered on Oracle:

select 1 ...

12. Select not returning result in hibernate    stackoverflow.com

I have schema in my database to which i have only select grants.Now when I am trying to use hibernate Criteria to get my list i am not getting result.The sql ...

14. How do I get count of what would be returned by Hibernate query object?    stackoverflow.com

I have a chunk of code that gets handed an arbitrary org.hibernate.Query object. This query is not a 'count' query. How do I get the number of items that would be ...

15. Sql count returns a strange value in Hibernate    stackoverflow.com

I created a query which suppose to return a number of counted rows. I tested my query using mysql query browser and it worked absolutely fine(it returns the correct result). However, ...

16. Problem with HQL query -- to return few columns of a Table    coderanch.com

Hi, Iam using HQL (Hibernate) to query a Table for selecting few fields of a record of the Table in the DataBase. My Query is like the Following, Here Iam selecting 2 of the 20 Cloumns of my Persisting Object - ModelDTO.... So, I've Created a New DTO with these two fields and Have written my Query as the following: String ...





18. Querying with JPA, returning all...Good or Bad?    coderanch.com

i have a question for you, somebody told me that is not a good practice when you have an EJB to use the method findAll() cause it makes the server gets down when it returns a big amount of entities however i want to make sure that this might be a possible issue for this to happen. I think that if ...

19. Hibernate return groups of sorted objects    coderanch.com

Is there a way in hibernate i can query and return the results grouped together by a a certain value, maybe in a List of Arrays or something like that? i know its kind of hard to explain but if i queried and got a result like this. [[1,1,1],[3,3,3],[6,6,6]] the number is just the property Im querying but it would actually ...

20. 'Simple' Hibernate query not returning any results.    coderanch.com

Hi, I was just wondering if someone could help me with what is no doubt an obvious error in my code below... I have the folling piece of code, which when I change the HQL to "FROM Customer" does return a list of all customers in the table customer. But when I include the 'WHERE' clause, and pass over a usernbame ...

21. JPA Hibernate: Does a Query not return a proxy collection?    forum.hibernate.org

Hello I am using JPA with Hibernate (v3.3.1.). Something astonsihes me. When I do a query I noticed that the returned list is a normal "java.util.ArrayList". I expected a kind of proxy collection so that it supports a "lazy loading" (loading of the list elements itself at run time when needed) means if I would later iterate over the list that ...

22. [SOLVED] nothing returned by find or loadAll    forum.hibernate.org

Newbie Joined: Tue Sep 25, 2007 6:30 am Posts: 10 Hello ! I'm beginning with Hibernate, using Spring and H2. My problem is i created a table Person (initialized by an initializing bean from spring). I create a person via hibernate (create an entity by new Person() and set props, then i call getHibernateTemplate.save(person)). This works because a direct jdbcTemplate SQL ...

23. Help: query return wrong arraylist    forum.hibernate.org

[b]Hibernate version:3.1[/b] Hi to all, I have a mysql view, that make a join bewteen 2 tables (mysql). When I launch a query by java-hibernate on this view, the code generated is correct (read with debug in the java console) and returns a correct arraylist of objects. But the criteria list (crit.list()) return a wrong arraylist of objects, where the last ...

24. Two query return same object    forum.hibernate.org

Hi, I'm writing an application for displaying timetable. Data are stored in a tiers database. I access data via hibernate. I'm using spring and hibernateTemplate. I'm trying to get data for two weeks. In database, events are stored with week numbers as a string (a string representing all week for a year, you must have a Y in order to get ...

25. query of Joined table returns duplicate entries    forum.hibernate.org

// This query retirns 1 entry, as expected Query query = (Query) txFactory.getSession(tx).createQuery("from PostTxTask"); List tasks = query.list(); ...

26. what is returned in the below HQL Query?    forum.hibernate.org

Hi, I am executing the below HqL query-- select v.visitId as visitId, max(v.startDt) as startDt from com.zts.hygeia.dao.Visit as v where (v.visitStatus!='SC' or v.visitStatus!='CL') and v.visitType.visitCategory='ENC' and v.patient.patientId = :patientId group by v.visitId It is returning a list of objests. and I need to get the values in a object . I tried casting it to a custom class with integer and ...

27. Hibernate query returning nothing from a non-empty database    forum.hibernate.org

I have a Hibernate query inside a DAO class that is supposed to return all rows in a table. Instead, it returns nothing. I have verified that rows are present in the table. Here is my method. Can anybody advise me on this? Thanks in advance. Code: public static List getAll() { ...

28. Join-Query with 1:n childList returns to much equals Objects    forum.hibernate.org

Author Message spring_alex Post subject: Join-Query with 1:n childList returns to much equals Objects Posted: Fri May 07, 2010 6:03 am Newbie Joined: Sun Aug 24, 2008 3:21 pm Posts: 8 Hi. Can anybody explain me, why i get dublicate Objects (same instanzes) from the resultList of an namedQuery and Joint Fetch? I have a Object Person with a ...

29. Connecting to database but Query returns 0 results??    forum.hibernate.org

Author Message bontakun Post subject: Connecting to database but Query returns 0 results?? Posted: Sun Jun 06, 2010 11:14 pm Newbie Joined: Sun Jun 06, 2010 11:00 pm Posts: 5 Hey I'm using Hibernate with Eclipse and I seem to have set this up correctly and I'm connecting to my petclinic database. I gathered that I'm successfully connecting becase ...

30. Query to return only superclass    forum.hibernate.org

Hi, I'm trying to query for a table where I only want superclass data without any subclass info. I have classes currently setup as Class A { int x } Class B extends A { int y } With tables that look like A id=1, x=1 id=2, x=5 B id=1, y=2 I'd like a query of table A to return ONLY ...

33. joined criteria query returns same instance multiple times?    forum.hibernate.org

Hello, I am working in a Java framework where I want to restrict an hibernate query, where I have to do a simple join. But hibernate seems to return the same result multiple times: a Deal refers, through its member creator to a User. A User has a field username. My restrictive code is: criteria.createAlias("creator","cr").add(Restrictions.eq("cr.userName", session.getPrincipal().getName())) It works only I get ...

34. return an hashmap from a sql named query    forum.hibernate.org

List resList = session.getNamedQuery("getStudentNameAndAddressStreet" ).list(); for (Object[] row: resList) { System.out.println( row[0] + " "+ row[1] ); ...

35. Query witch returns more than one class    forum.hibernate.org

Let's say I wanted to do the following query: List res = session.find("select foo, bar " + "from eg.Foo foo, eg.Bar bar " + "where foo.startDate = bar.date" ); What's in "res"? Is res.get(0) a list of classes of "eg.Foo" and res.get(1) a list of classes of "eg.Bar"? I'm having problems returning the two lists of eg.Foo and eg.Bar in the ...

36. Query returns result in wrong order    forum.hibernate.org

List ids = ... Query query = pSession.createQuery("select from BOCustomer as customer " + "where customer.id in (:ids)"); query.setParameterList("ids", ids); List results= query.list(); ...

37. select query returning property    forum.hibernate.org

Hi all, I have a problem with (basically) the following hql query: "select person.name, ... from Person left join person.contacts ..." DB2 gives me an error saying: SQL0206N "AS" is not valid in the context where it is used. Looking at the generated SQL query, I see the following:" "SELECT ...., someTable.someColumn AS x3_0_, AS x4_0_ from PERSON ..." So, the ...

38. How to ue subqueries that return a multiple valies    forum.hibernate.org

Hi, I am using NamedQueries in my Hibernate object. My Named query is like Code:

39. Same EXACT code yet session.find returns wrongly    forum.hibernate.org

Newbie Joined: Thu Apr 01, 2004 6:28 pm Posts: 15 I have ALMOST the same function but for some reason session.find returns me very wrongly. I've struggled with this for almost five hours and I'm giving up Here is the right code, that returns INSTANCES of Product CLASS Code: public Collection findProductsByProductsIds(Map argMapProductsIds){ List foundProducts ...

40. Select item.name from Item as item..doesnt return object    forum.hibernate.org

Hi, I am new to hibernate. I want to load all the instances of an object which has some one to one relation. I dont want to load this relations when I fire select query. I am using "Select item.name,item.desc from Item as item" as the query. I just want to retrieve name and description of the items. But query.list() doesnt ...

41. Query returning different results    forum.hibernate.org

List list1 = s.createCriteria(Order.class) .createCriteria("items", "item") .add( Expression.eq("item.name", "p123") ) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .setMaxResults(5) List list2 = s.createQuery( "from Order order " " where exists ( from items as item where item.order = order and item.name= :name ) ) .setParameter("name", "p123") .setMaxResults(5) .list(); Is there a way to make the first query behave like the second?

42. Query returning different results    forum.hibernate.org

List list1 = s.createCriteria(Order.class) .createCriteria("items", "item") .add( Expression.eq("item.name", "p123") ) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .setMaxResults(5) List list2 = s.createQuery( "from Order order " " where exists ( from items as item where item.order = order and item.name= :name ) ) .setParameter("name", "p123") .setMaxResults(5) .list(); Is there a way to make the first query behave like the second?

43. select returns new Object    forum.hibernate.org

44. distinct with order by returning incorrect results    forum.hibernate.org

Using Hibernate 2.1 against MySql 5. When I perform a distinct with an order by on the same column in the same table, Hibernate returns an unordered result set. For example: Here is my Java hql: String hql = "select distinct aircraft.platform from Aircraft aircraft order by aircraft.platform"; Here is the prepared statement generated by Hibernate: select distinct aircraft0_.PLATFORM as x0_0_ ...

45. Returning collection from report query    forum.hibernate.org

46. Query returning only one result?    forum.hibernate.org

Hibernate version: 2.1.6 I have a query returning an array of 2 objects while I would expect it to return a 3-objects array. The query is: select category, categoryLevel1, categoryStore1 from Catalog as catalog, CategoryStore as categoryStore1, CategoryStore as categoryStore2 inner join catalog.catalogCategories catalogCategory inner join catalogCategory.catalogCategoryPK.category category left outer join fetch category.categories categoryLevel1 left outer join fetch categoryLevel1.categories categoryLevel2 where ...

47. HQL and Criteria Query return different results    forum.hibernate.org

Hibernate version: 2.1.6 Mapping documents: Code: ...

48. session.find returning stale results    forum.hibernate.org

The other application is not using hibernate. That is the root of the problem. I am not able to use session.clear() because that makes the query take 8 seconds per use. This page is supposed to refresh every 10 seconds, so that would not make sense. This is not really a great place to use hibernate, except for the OR mappings. ...

49. Find returns several recorcs when there is just one in db :(    forum.hibernate.org

list = getHibernateTemplate() .createCriteria(session, Someclass.class) ...

50. Query returns duplicate objects when it shoudn't    forum.hibernate.org

I am mapping a class hierarchy to a single table. One of the subclasses has a list associated with it which is stored in another table. Since the list is small and I need it all the time, I set it to lazy="false" and outer-join="true". When I execute a query, if there are any subclasses in the database which are of ...

51. HQL count(*) should return Long?    forum.hibernate.org

52. Projections.rowCount returns incorrect value    forum.hibernate.org

...

53. Named query returning Object    forum.hibernate.org

Hello: I'm using the Hibernate 3.0 XML Mapping feature, that seems great for me, because I'm presenting data using XSL filters. Now, I have a little question: I'm trying to execute a named query. If I use the query of the form: "from User" I have the result as a List of Elements. Now, if I specify the query as: "select ...

54. How to identify whats returned by a named query?    forum.hibernate.org

Hello, I'm using hibernate 3. Suppose I do the following named query: Is there a way to look in the list returned and know that a certain array element is a certain column or object? Sort ...

55. Query.uniqueResult() returns proxied object    forum.hibernate.org

Author Message cbredesen Post subject: Query.uniqueResult() returns proxied object Posted: Tue Jul 19, 2005 9:11 am Red Hat Associate Joined: Mon Aug 16, 2004 11:14 am Posts: 253 Location: Raleigh, NC I'm running an HQL query for the below entity. In a JUnit test, the entity is returned normally. In one of my business calls (to the same method, ...

56. Returning typesafe objects from sql queries ?    forum.hibernate.org

57. returning multiple objecets from a query    forum.hibernate.org

Query query1 = session.createQuery("from OrderBean order,CustomerBean customer where order.intCustomerId = customer.customerId"); List orderList = query1.list(); org.hibernate.type.Type []typeArray = query1.getReturnTypes(); for (int i=0; i

58. Return level via sql query using Oracle CONNECt BY    forum.hibernate.org

Hi all, Im using Oracle 9i along with Hibernate in order to generate an organisation hierarchy. I have created a native sql query using the Oracle CONNECT BY clause and it works fine through hibernate. However, now I need the level attribute (or column or whatever) that can be called via the CONNECT BY statement to be returned via sqlQuery.list as ...

59. returning column names of a named native sql query    forum.hibernate.org

is it possible to get the column names out of a native sql query defined in a namedquery hbm.xml file like this select id , name,description from StpQueue where browseflag = :flag if i uncomment the return-scalar part by calling namedSQLQueryDefinition.getScalarQueryReturns(); iam able ...

60. Returning a the class based on query name    forum.hibernate.org

I am using named query. I execute this as using the following implementation: Query q = session.getNamedQuery("eg.cat.search.by.name"); q.setInteger(0, intKeyValue); b = q.list(); session.getTransaction().commit(); I want to return the name of the class in the Hibernate mapping. Eg, in the following mapping, I want to return "com.coname.moda.Static.Acctcntr" Thanks for your help. JJ

61. Hibernate with Projections not returning the values???    forum.hibernate.org

Hi, The hibernate version is: 3.0 Mapping Document is: RStateReasonCodesDTO Database Version is : 9.0 I have the following query in Hibernate projections which is actually returning a list size 5. Which is right, when i try to get the value from the DTO (Which is not null) but the values i am getting from it using getters are null. What ...

62. Hibernate query to return sorted collection    forum.hibernate.org

63. Taking advantage of Oracle's RETURNING clause    forum.hibernate.org

64. Select with "and 1=2" returns no results    forum.hibernate.org

Newbie Joined: Wed May 24, 2006 5:11 pm Posts: 4 Need help with Hibernate? Read this first: http://www.hibernate.org/ForumMailingli ... AskForHelp Having an interesting problem. I have an entity, Parent, which has a one-to-many relationship with Kid. Each kid has a Parent. I can retrieve a Parent by id, and get with it all of its kids, no problem. But when I ...

65. criteria projection should return the object itself    forum.hibernate.org

I am doing a criteria projection query which joins two tables. this is a little weird, but I also want the object of the original criteria. The only Projection I can see to use is a field of the original object, but not the object itself. I need a "this" or something keyword or new projection type. I see I can ...

66. Native SQL Query returning my object and my joins!    forum.hibernate.org

I have a Native SQL Query that I'm mapping using hibernate. It works, but the return type from the list call returns a List of Object arrays that contains 3 objects: UntypedDocumentInstances, BinaryData, and Namespace. The last two are just joins to optimize the query. How do I just get the UntypedDocumentInstances? I thought that's what setEntity was for? I was ...

67. HQL "select count(*)" returns Long?    forum.hibernate.org

68. HQL Query using utf8 - Incorrectly returns zero results.    forum.hibernate.org

Newbie Joined: Tue Jun 20, 2006 10:20 pm Posts: 6 While updating my application to use all utf8 characters i've run into a strange problem. I can save, get, manipulate, log in full UTF8 mode. The only query i'm having a problem with is getting a list of tutor transactions (we have a database of log files from students working through ...

69. Getting Hibernate to return results in order    forum.hibernate.org

I'm using Hibernate in my current project. I have a class TreeNode that has a Set getChildren() method. I would like to somehow convert this to something like List getChildren() and make sure the list is returned in order as determined by the getName() value of each TreeNode. I realize that I could code up the getChildren method myself, returning an ...

70. HQL query for one class returning multiple classes    forum.hibernate.org

I think this is a newbie question, so if there's a link to documentation that explains what I screwed up and what I'm supposed to do, thanks in advance. Environment (in part): JDK 1.5.0 Update 6, Hibernate 3.1.3, mySQL 5.0.22, Eclipse 3.2, MyEclipse 5.0 Here's a distilled version of my situation (hopefully): I have two objects, Submission and SubmissionStep. I'm querying ...

71. hql query to return constat(s)    forum.hibernate.org

hi! i want to use an hql query (that could run for Session.createQuery) to return a constant value or a list of constant values. i tried: select 'buc' from Sfa_categorii as c where 0?]... a similar sql query runs ok on MySql: select 'buc' ...

72. Returning java.util.Set from Query does reordering    forum.hibernate.org

String strQuery = "select assetsScenarios " + "from Asset myasset " + "LEFT JOIN myasset.assetsScenarios assetsScenarios " + "WHERE ...

73. Query on date returns no results    forum.hibernate.org

Marco, Thank you so much for your answer. It works! But, I prefer not to use the to_char function because I don't want to add any sql function to it. I would like to be able to do with the following code: Calendar cal = Calendar.getInstance(); Criteria criteria = session.createCriteria(Payment.class); criteria.add(Expression.eq("orderDate", new Date(cal.getTimeInMillis())); where orderDate is a property of the pojo ...

74. Named query returning repeating results    forum.hibernate.org

Newbie Joined: Mon Sep 18, 2006 6:34 am Posts: 18 Hi, I'm having a problem with the results of a named query. When I run the query from the mapping file below in query analyzer with the parameters substituted from the values set in the java code, I get 104 records back, each of them unique. However, when I run the ...

75. Hibernate query not returning results    forum.hibernate.org

I have a simple Hibernate code. The query does not work in the sense that even though the table has entries,nothing is returned. Any help is appreciated. I am using Hibernate 3.2 and Cloudscape 10.1 Hibernate.cfg.xml ------------------------ org.apache.derby.jdbc.EmbeddedDriver jdbc:derby:JPracticeDB;create=true org.hibernate.dialect.DerbyDialect