order « Query « JPA Q&A





1. Hibernate ordering    stackoverflow.com

I have the Vehicles class and mapping file for it and i want to get all rows from vehicles table ordered by ID desc (I also need the same for my ...

2. Hibernate: ordering a Set    stackoverflow.com

I have a class Person who has a set of Books. It is not meaningful in the particular case to have an ordered or sorted collection. Say now that I have a ...

3. Hibernate Criteria - Order By    stackoverflow.com

I have currently the below criteria :-

Criteria addr = criteria.createCriteria("location.address"); 
                addr.add((Restrictions.and(Restrictions.between("latitude", latmin,    ...

4. Hibernate Criteria Order By    stackoverflow.com

I have a table called Gift, which has a one-to-many relationship to a table called ClickThrough - which indicates how many times that particular Gift has been clicked. I need to ...

5. hibernate how to order set in hql    stackoverflow.com

I understand if I use

  class Fund{
      private Set<FundClass> fundClasses =  new LinkedHashSet<FundClass>();
      @org.hibernate.annotations.OrderBy(clause="order asc")
    ...

6. ordering in JPA not working    stackoverflow.com

i'm using JPA with Hibernate implementation. I've a named query like in an entity MyTable :

@NamedQuery(name = "myQuery", query = "select val from MyTable val") 
The myTable entity is containing ...

7. Hibernate Order By    coderanch.com

Hi there all, I am really unsure how this is done. You know how sometimes on web sites you see an order by option like order by relevance and a percentage is retured with how relevant the record is to the entered search criteria. For instance say i have a table with tow columns Name and Age and 5 records in ...

8. [Hibernate]Order by using HQL    coderanch.com

I have a simple HQL that works without error but hibernate doesnt order my list. Is there any other way to do it then "order by"? my hql: FROM FrequenciaCrianca as fc WHERE fc.nucleo.codigo = 341 AND (fc.nucleoCrianca.dataTermino = null or fc.nucleoCrianca.dataTermino >= to_date('31/07/2008', 'dd/mm/yyyy')) AND fc.nucleoCrianca.dataInicio <= to_date('31/07/2008','dd/mm/yyyy')) order by fc.codCriancaPeti

9. Hibernate 2: HQL "order by"    coderanch.com

Hi, I need to get 5 most recent books called "The Book" from the db. I do this right? query = "select book from Book book where book.name = '" The Book "'" + " order by book.writtenDate desc"; Query q = hibSess.createQuery(query); q.setMaxResults(5); List b = (List)q.list(); } My concern is how it does it? If I have thousands of ...





10. Order and Item model in Hibernate    coderanch.com

I am designing an application where order has many items and order and items have statuses. When status of any item changes to available, order is retrieved and status of the all items of order are evaluated before changing the status of order from in-progress to complete. It seems pretty time consuming. Is there better efficient way to model this problem ...

11. Interception order    forum.hibernate.org

Hi all. I have the following (piece of) model: Code: @Entity @org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true) @Table(name="text") public class Text implements Serializable { protected Set subtexts = new HashSet(); @OneToMany(mappedBy="text") @Cascade(value = {CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE_ORPHAN }) private Set getSubtexts() { return subtexts; ...

12. Criteria order    forum.hibernate.org

Hi, I would like to sort my address by a number of the building. This number may consist of digits and letters (letters only at the end). I would like to sort this list using Criteria object. When I am using: Code: criteria.addOrder(Order.asc("address.firstNumber")); I got: 22A, 23, 24B, 3, 31 and so on... Of course I would like to have the ...

13. JPA 2.0 Criteria order by path    forum.hibernate.org

14. 1:n ordering    forum.hibernate.org

hi! i'm looking for a solution to the following problem: i have a post and a media table. a post has a set of media elements: Code: @ManyToMany(fetch = FetchType.EAGER) public Set getMedia() { return media; } the table structure looks like this: table post (title, text) table media (title, url) table post_media (post_pk, media-pk) now ...

15. Criteria order and assosiation order-by    forum.hibernate.org

Newbie Joined: Thu Jan 22, 2009 2:49 am Posts: 13 Hello i am having the following declarations Code: @Entity @Table(name = "EMPLOYEE") public class Employee implements Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column(name = "EMPLOYEE_ID") private Integer id; @Column(name = "EMPLOYEE_REGISTRATION_NUMBER") ...

16. HQL order by not working - wrong order ?    forum.hibernate.org





17. unable to parse order-by fragment: unexpected char: '-'    forum.hibernate.org

I upgraded from 3.2.4 GA to 3.6 final. I have an order-by statement containing a '-' used as a subtraction operator which worked in 3.2.4, now it throws the following error in 3.6: org.hibernate.HibernateException: Unable to parse order-by fragment at org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator.render(OrderByFragmentTranslator.java:66) at org.hibernate.sql.Template.renderOrderByStringTemplate(Template.java:694) at org.hibernate.persister.collection.AbstractCollectionPersister.(AbstractCollectionPersister.java:556) at org.hibernate.persister.collection.OneToManyPersister.(OneToManyPersister.java:84) at org.hibernate.persister.PersisterFactory.createCollectionPersister(PersisterFactory.java:104) at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:305) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:822) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:748) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1099) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:400) ...

18. order by does not work    forum.hibernate.org

19. SQL order by ... nulls first    forum.hibernate.org

Hello everybody, I want to sort my objects either ascending or descending but by adding null sort at the end of the result. I found that it is possible to do it using JDBC by either adding ORDER BY myField NULLS LAST but it does not work using MS SQLServer or MySQL. I found a workaround to do the same without ...

20. Order by as argument in the query ??    forum.hibernate.org

21. many-to-many and order-by    forum.hibernate.org

Hi, Hibernate 1.2.5 When I map a many-to-many collection and decide to order this collection with the "order-by" clause, then the generarted query shows the order-by on the joining table eg: ==> Hibernate: SELECT relat0.service_id, Servi1.service_id AS service_id0_,Servi1.date_creation as date_creation0_, Servi1.date_modif as date_modif0_, Servi1.service_name as service_name0_, Servi1.service_description as ...

22. how to add diffent products to one order?    forum.hibernate.org

I have some different products in several seperate tables: book: --- book_pk --- title --- price --- author .... CD: --- cd_pk --- subject --- price --- numOfSongs ... etc.. And I use one order table to store all kinds of order: order --- order_id (pk) --- product_type --- product_id (refers book_pk and cd_pk) --- order_time .... Does hibernate support this? ...

23. how can a change order of insertions    forum.hibernate.org

i have an object A depending to an object B. A is mapped with a many-to-one-relationship in mapping file of B. the ID of B is an not-null-field in table of A. my problem is that A will be saved earlier than B and because of B is not saved yet I get a NOtNullViolationException from database. Mapping B:

24. order-by with a many-to-many set    forum.hibernate.org

Normal n to n relationship: Code: foo <-- foo2bar --> bar Can I order the Set foo.bar using a column of bar; bar.name for instance? the .hbm. xml for the attribute foo.bar: Code:

25. Order.asc(...) ??    forum.hibernate.org

Regular Joined: Wed Aug 27, 2003 2:55 am Posts: 90 Location: Sweden Hi, Have a look at this code: Code: /* (non-Javadoc) * @see eriksson.andreas.dao.CityDao#findByName(java.lang.String) */ public City[] findByName(String cityNameToFind) { Session session = this.obtainSession(); try { Criteria criteria = session.createCriteria(CityImpl.class) ...

26. Hibernate 2.1 ORDER BY with JDK1.3.X    forum.hibernate.org

In the latest 2.1 documentation, I read that JDK1.4 is necessary for the ORDER BY clause to be used in an HQL query. I do not have the luxury of using JDK1.4 because my application server does not support it. I would like to use Hibernate as my persistence mechanism but I MUST HAVE ORDER BY for my queries. Is it ...

27. ordering sets...    forum.hibernate.org

this is probably a trivial question, but I'm trying to get a set from a parent-children connection, (parent.getChildren() )but I can't see how to define the ordering of the child set. for instance, the child mapping has an int (childID), a string (childCode), and a date (childRegDate). I would like to be able to get these as sorted lists on the ...

28. is ordering a pageable query possible?    forum.hibernate.org

I have a pageable query set up and would like to order by a column in the underlying table but it doesn't appear to be possible. I want to pull rows out 15 at a time but order the entire table of 1000+ rows by different columns depending on what the user selects. I looked at the sql generated by hibernate ...

29. Criteria - Order    forum.hibernate.org

30. ... order by?    forum.hibernate.org

Hi all! I'm trying to create an HQL query, and order it, but I'm having some trouble, due to subclasses I guess. This is my mapping: Code: ...

31. how can I order by this    forum.hibernate.org

Visit Code: ...

32. many-to-many ordering (again)    forum.hibernate.org

Newbie Joined: Tue May 18, 2004 7:46 pm Posts: 1 Hopefully this is an easy one. I've looked around and no one seems to be asking this question. In a nutshell, the question is: how can you specify an order-by clause when you have an index table mapping a many-to-many relationship? Consider the case of Documents and Authors: Document docid name ...

33. Trouble with hql order by    forum.hibernate.org

...

34. ORDER BY Parameterization    forum.hibernate.org

This is not a hibernate query per say, just a general SQL question, but since everyone here is dealing with SQL, I thought I'd ask it to you guys. I have 2 questions : We cant pass in parameters to ORDER BY or GROUP BY in JDBC PreparedStatements. This leads me to believe that the SQL Compiler cannot do dynamic ordering ...

35. About Hibernate's SQL execute order    forum.hibernate.org

if (user.getPasswd().equals(passwd)) { user.setStatus("Login"); System.out.println("1-------------"); officerDAO.update(user); } SysLog sLog = new SysLog(); sLog.setOfficerCode(user.getOfficerCode()); sLog.setDetail("Test system log."); System.out.println("2-------------"); ...

36. Simple Ordered Many to Many    forum.hibernate.org

Hi, I've been trying to use the bag/set method, but I've been unable to add the 'element' or 'index' to the bag. Here is how far I've gotten so far. Code: ...

37. order by avg(XX) in hql    forum.hibernate.org

...

38. Set order-by does not order correctly    forum.hibernate.org

39. Order of hibernate operations    forum.hibernate.org

41. Loosing order in HashSet, other possibilities or solutions?    forum.hibernate.org

Hello Sorry if I might bother someone. Some people helped me to step into a better situation but there is still one issue which I cannot solve. The initial issue was that if I joined tables the resultset was not distinct and so I got indistinct results in the parent/child relationship of service/mmsAbo. In fact I had 1000 services where there ...

42. How can I order sub criteria ?    forum.hibernate.org

43. NamingStrategy and order-by....    forum.hibernate.org

44. Set and Order    forum.hibernate.org

Read the rules before posting! http://www.hibernate.org/ForumMailingli ... AskForHelp Hibernate version:2.1.6 I have three tables as the following: create table book ( id bigint not null, title varchar(255) not null, publish_date date, primary key(id) ); create table book_author( book_id bigint not null, author_id bigint not null ); create table author( id bigint not null, name varchar(63) not null ); Thes mapping file ...

45. order by nulls last    forum.hibernate.org

It is problematic for the developer to not have control over sorting of nulls. In different DBs, the sorting of nulls relative to other values is handled differently. PostgreSQL - Nulls are considered HIGHER than non-nulls. DB2 - Higher MSSQL - Lower MySQL - Lower Oracle - Higher "NULLS LAST" is part of the SQL 99 standard. The syntax is as ...

46. Order-by and Hibernate 3.0    forum.hibernate.org

Hi, I have an issue with Hibernate 3.0.5: my application hangs up (no exception) when it tries to access a Set (lazily loaded) with an order-by clause specified in the mapping file. When I disable the order-by, it works well. I am using the JDK 1.5, SQL Server 2000 SP4, C3P0 0.9.0pre5 and the INet JDBC Merlia Driver. May be someone ...

47. PersistentSet and ordering    forum.hibernate.org

Hi, Using Hibernate version: 3.0.5 I'd like to find out if the current PersistentSet (org.hibernate.collection) has an ordering. The ordering was specified in the mapping file using It would be very helpful to know of which type org.hibernate.collection.PersistentSet.set is or to have a flag "hasOrdering". But I can't find any public infos about ...

48. Criteria and specific order    forum.hibernate.org

49. many-to-many with order    forum.hibernate.org

50. ordering query dynamicly    forum.hibernate.org

Hi, I have a simple query string like "from Customer as cust join Cars as car where car.id = cust.carId" I need a way of adding order by dynamicly, so I can generate queries like this: "from Customer as cust join Cars as car where car.id = cust.carId order by cust.id" or "from Customer as cust join Cars as car where ...

51. DistinctRootEntityResultTransformer mangling my order?    forum.hibernate.org

Hibernate version: 3.0.5 and 3.1.2 I have the following code: result = session.createCriteria(Services.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .setFetchMode("ports", FetchMode.JOIN) .createAlias("ports", "p") .addOrder(Order.asc("name")) .addOrder(Order.asc("p.portNumber")) .list(); Basically I have a Services class that has an ID, name, description, and a set of ports. This query eagerly fetches the collection of port objects that is associated with a service. This would result in duplicate service rows being ...

52. order-by    forum.hibernate.org

not entirely sure what you're asking.. are you asking what if the underlying DB doesn't support having the 'lower' command after the words 'order by'? I would say the easiest way is to simply change the mapping files on a case by case basis. The beauty of having this stuff in xml files is that it doesn't require recompiling the project ...

53. Parameterised order by direction    forum.hibernate.org

Hi, I'm trying to do the following with HQL: Where :arg_0 is a parameter representing sort direction e.g. asc or desc. Running this gives: org.hibernate.hql.ast.QuerySyntaxException: unexpected token I believe parameters can be used in the order by clause; am I to assume that they cannot be used ...

54. Ordered many-to-many set?    forum.hibernate.org

I have a many-to-many Set mapping, and I want to order the set on a property of the associated class. (Class Member has a Set 'categories' of class Category.. I want this set returned in order by Category.name). I think I can't use "order-by" in the mapping, because that wants a column name in the table, which in this case is ...

55. Order by Many-To-One    forum.hibernate.org

Let's say i have entity "Terminal" that has many-to-one relation to entity "TerminalStatus". My colleague wrote following code for sorting and filtering terminals by Terminal entity fields(like terminal number, terminal name, etc): ... criteria.setFirstResult(first); criteria.setMaxResults(max); criteria.addOrder(Order.desc(order)); // order - properties of Terminal Collection terminals = criteria.list(); ... But it turned out i also need to sort em by TerminalStatus.code, another words ...

56. order-by and LinkedHashSet    forum.hibernate.org

select firm0_.id as id3_0_, employees1_.id as id7_1_, employees1_.first_name as first2_7_1_, employees1_.last_name as last3_7_1_, employees1_.firm_id as firm14_7_1_, employees1_.firm_id as firm14_0__, employees1_.id as id0__ from firm firm0_ left outer join employee employees1_ on firm0_.id=employees1_.firm_id where firm0_.id=1 order by ...

57. Criteria Order    forum.hibernate.org

Sorry - been away for a while. If you've added a setFetchMode on customerPostalAddress and you are still getting a lazy exception when accessing it in a class - see if customerPostalAddress has a relationship to another table on which you are trying to access from the class but have not added a setFetchMode. e.g. customerPostalAddress.country

58. In trouble with Ordering    forum.hibernate.org

59. Criteria and order by concat    forum.hibernate.org

60. Does order of calling saveOrUpdate matter?    forum.hibernate.org

Here are two class snippets and the associated HBM files. Code: public class Address implements Serializable { protected Long addressID; protected String street; protected String city; protected String state; protected String zip; protected Set people; } public ...

61. Order by greatest in HQL?    forum.hibernate.org

Thanks for the reply. I had done it in native SQL, but I felt that this feature is so common that it must be supported by almost all DB types and therefore must be supported by HQL. The application that I am developing needs to support multiple DB types in the future, so I am a bit reluctant to use native ...

62. order many to many    forum.hibernate.org

63. Order by broken!?    forum.hibernate.org

select book0_.id as id4_, book0_.version as version4_, book0_.read_count as read3_4_, book0_.pdate as p4_4_, book0_.title as title4_, book0_.publish_date as publish6_4_, book0_.description as descript7_4_, book0_.link as link4_, ...

64. Order by using Criteria    forum.hibernate.org

Hi, I have 2 tables named Forms and FormPages. Forms have one to many relationship to FormPages table. The Forms entity can have multiple FormPages entities in it. I need to retrieve all Forms with the FormPages sorted by a key in the FormPages table named Pageorder . I have written the following code for that: List formslist =HibernateUtil.getCurrentSession().createCriteria(Forms.class) .createAlias("formpageses","formpages") .addOrder(Order.asc("formpages.Pageorder")) ...

65. Order by in Criteria query    forum.hibernate.org

66. Order By with Criteria    forum.hibernate.org

67. Order query by priority    forum.hibernate.org

68. Hibernate selecting order    forum.hibernate.org

Hi! I 'm looking for any information regarding next problem: Database for my application is shared for two applications: my java application and Old C++ application. In C++ there is business logic which depends on order of reading data from db. That is: reads data from db and immediately process them. Order of readed data is natural: as they located in ...

69. HQL ORDER BY is ignored    forum.hibernate.org

Hello, I've Googled and found no obvious answer to this question. I suspect I'm reporting a feature rather than a bug, but the behaviour does seem a little strange. If I execute some HQL: from Order o order by o.name then the SQL generated includes the ORDER BY statement that we would expect. However if I execute something like this: from ...

70. order of insertions    forum.hibernate.org

I am using hibernate core 3.2.6ga with hibernate annotations 3.2.1ga. I have an object model with ~20 classes using 1:n bidirectional relations. The model is ERM model is not "tree like", however has one root object. Unlike tree, parent's grandchildren can have relation with 2 parent's children. All relations are annotated like that: Code: @Entity @Table (name="stack") public class Stack { ...

71. Hibernate order by query thru java solution urgently reqd    forum.hibernate.org

hi, i am using java with hibernate . i want to run a hibernate order by query thru java. i have written the query in hibernate.hbm.xml file. the query is as follows: query SELECT distinct a.process_id, a.name name, a.category_id,c.parent_id FROM tbl_process_master a, tbl_category c where (lower(a.name) like :searchString or lower(a.description) like :searchString or lower(a.meta_tag) like :searchString ) and a.status=:status and a.category_id=c.cat_id ...

72. easier way to order by    forum.hibernate.org

Hibernate version:3.2.6 I have the following mapping, when I have Circuit object, I can get users by circuit.getUsers(), which is sort by user id. But in another jsp, I have to display users by user name. I want to sort it on database level, I have to write another DAO or define another set mapping. Is there a easier way? Thanks ...

73. Can I force the order in which Hibernate sends sql?    forum.hibernate.org

I have a class which maps to a join table as a set. I also have another class which calls a stored procedure. The stored procedure is looking for the data in the join table. The problem is that Hibernate generates the sql for the join table after all other inserts, so the stored procedure gets called before the join table ...

74. order by "set is empty"    forum.hibernate.org

75. order by chromosome    forum.hibernate.org

76. Order    forum.hibernate.org

Hi everybody, I just need help with the order, I'm using criteria. I have a class Exam that have a OneToMany relation with a class ExamQuestion, and in this class I have a ManyToOne relation with Question and another relation with Exam and it's also ManyToOne. Question have a ManyToOne relation with Area and area have the property areaName. I'm retriving ...

77. Ordering in Hibernate    forum.hibernate.org

78. HQL union and order by    forum.hibernate.org