Sort « Query « JPA Q&A





1. hibernate sorting    stackoverflow.com

hey i want to do nested sorting in hibernate. i has a set of application in course object .application has a time and type attribute I want to sort by type first and ...

2. database sort vs. programmatic java sort    stackoverflow.com

I want to get data from the database(MySQL) by JPA, I wand it sorted by some column value, So, what is the best practice, to: Retrieve the data from the database as list ...

3. How to perform locale based sorting while using hibernate as ORM    stackoverflow.com

I use server based sorting(in the db) using orderby clause. But now that I want to support multiple locales, how should I pass the locale information to the DB via ...

4. Sort hibernate collection when retrieving from database    stackoverflow.com

I have an object Foo with a list of Bar. Is there a way I can set up my class so that getBars() will return a List that has been ...

5. SQL: grouping by column after sorting    stackoverflow.com

Given a table structure with name and rank columns, with the possibility of there being duplicates for name, how can I get the rows unique by name, with maximum rank? For example, ...

6. get the Sorted result with sql in hibernate query    stackoverflow.com

I need to get the Sorted List based on Number but i have that number in table as a CHAR. When m trying with Order by number than the result will be ...

7. How should I add sorting to an Apache Wicket DataTable with content from Hibernate?    stackoverflow.com

I have an existing DataTable built in Wicket 1.5 as follows: The Page's java file.

public class ExamplePage extends WebPage {
public ExamplePage(){
List<IColumn<Example>> columns = new ArrayList<IColumn<Example>>();
columns.add(new PropertyColumn<Example>(Model.of("name"), "name"));
ExampleProvider provider = new ExampleProvider();

  ...

8. Hibernate: sorting with Join    stackoverflow.com

I have two tables: resumeId and CandidateInfo.

String sql_query = "from shared.SelectedResumes as sr " +
                 ...

9. HQL Order By Class is not Sorting    coderanch.com

Hello, I have 2 entity classes, Menugrop and Catgroup. Mengroup has one to many relationship with Catgroup. In Mengroup, private Collection catgroups = new LinkedHashSet(); I write the below code to fetch Menugroup and it's catgroup. String sql = "select distinct m from Menugroup m left join fetch m.catgroups c where m.published=true and c.published=true order by m.name asc, c.name asc"; Query ...





10. Sorting results by column in Hibernate    coderanch.com

I'm having trouble sorting by a specific column. If I sort by participantTypeId it works. But if I sort by sortColumn then I receive an error. But both columns are in the DB and mapped correctly (I think) public List loadCaseParticipantsForCase(final Integer caseId) { final DetachedCriteria criteria = DetachedCriteria.forClass(CaseRecord.class); criteria.add(Restrictions.eq("caseRecMaster.caseMasterId", caseId)); criteria.add(Restrictions.eq("activeFlg", CaseRecord.YES)); criteria.setFetchMode("caseRecMaster", FetchMode.JOIN); criteria.setFetchMode("participant", FetchMode.JOIN); criteria.setFetchMode("luParticipantType", FetchMode.JOIN); //criteria.addOrder(Order.asc("luParticipantType.participantTypeId")); -- ...

11. Hibernate sorting - is there a better way?    coderanch.com

I'm using Hibernate with an embedded derby database. I have a parent child relationship between two classes, Think of it as a checkbook application with Accounts and Checks. My form is a master-detail set of jtables with the top being the Accounts and the bottom Checks, When you click on the accounts the detail changes to the checks in the account. ...

12. Hibernate Sorting Problem    coderanch.com

Hi, I have a situation where in i need to sort the records based on the status. The status value could be ACTIVE/PROCESSING/COMPLETED/TERMINATED. Now i want to get the records like first i want to get all the ACTIVE records, then PROCESSING, then COMPLETED and then TERMINATED. If i directly sort on status column i wont get the desired result. So ...

13. HQL paginateing and sorting problem    coderanch.com

Hi all I have simple html grid (html table) displaying page 5 of 10 pages (each page contain 5 rows) currently when i sort the grid - the page data is lost (because i am sorting all results not just page 4 results) I would like to sort just the results of page 5 , Is it possible to sort the ...

14. Secondart sort using criteria api    forum.hibernate.org

15. Is it possible to sort before grouping?    forum.hibernate.org

I am trying to sort using "order by" _before_ grouping with "group by" but it does not seem to work. The grouping works fine but the ordering is ignored. I am using Hibernate 3.2.6. The hibernate query is of the form: "from Customer where id in (select id from Customer order by id desc) group by companyName,siteName" The part in parentheses ...

16. Sort By difference of two columns    forum.hibernate.org





17. Help Required to Sort by using criteria interface.    forum.hibernate.org

I have a table employee. The table structure is as follows empid empname 1 vinay shetty 2 arun kumar 3 prashanth malhotra 4 akshay dubey 5 praveen kini 6 mukund pai Now i need to write a query by using Criteria such that the result should be in the sorted of last name.(Shetty,Kumar,Malhotra..). Corresponding SQL query for mysql is as follows ...

18. Can one use @Sort with comparator without Comparable?    forum.hibernate.org

public void addTrial(ClinicalTrial trial) { if(trial == null){ return; } getClinicalTrials().add(trial); trial.getCentres().add(this); }

19. Many-to-Many and sorting    forum.hibernate.org

Hi alls. How could i set "order-by" condition in such case: Table A { .... } Table B { .... position integer } A <-- many-to-many --> B = A <-- C -- > B so my mapping looks like this: Now i want to ...

20. stupid problem with sorting    forum.hibernate.org

I'm trying to maintain a sorted set of Subjects in a Study object. Subjects should be sorted by their name property. I have been using the order-by attribute and a LinkedHashSet, but this results in an improperly sorted set immediately after adding a new Subject. I thought the proper workaround would have been to use the sort="natural" attribute, a SortedSet object, ...

21. Sort options for one-to-many    forum.hibernate.org

Firstly my apologies if I should have been able to work this out from the documentation but I've been staring at the problem with no progress too long so I'd appreciate any help. I have a simple one-to-many relationship and I have two requirements: 1. That the getter for the many side returns the results in a particular order. This I ...

22. Sort not possible with computed column    forum.hibernate.org

At *first* view, it seems that it is not possible to sort on a "computed" column (i.e. a property with a formula). It throws: net.sf.hibernate.QueryException: unresolved property: .... Why is Hibernate able to handle computed columns in SELECT clauses but not in ORDER BY clauses - (SQLally speaking it is well possible) ? Is there a particular reason (perhaps not all ...

23. Sorting Set    forum.hibernate.org

Hi, I have a Entity class, which have a Set property, that will be use as a Set of String. When I save it, I use HashSet, so the collection of String is not sorted when it go to database. I'm not using the attribute "sort" or "order-by" in the mapping. When I'm querying it, is it possible to get that ...

24. Sorting by pre-defined order    forum.hibernate.org

Hello, Is there a way to group objects by a pre-defined order? Here's an example of what I want to do: I have an "Document" object with a "type" attribute. I want to retrieve a collection of "Document" objects that are sorted by "type" in the following order: first "Word", secondly "Excel", lastly "PowerPoint". Thanks. Thomas

25. Retrieving and sorting collection using Criteria/HQL?    forum.hibernate.org

Hi what I would like to do is retrieve a collection of files from a SPECIFIC FileType object sorted using fileName or any of the other parameters inside the File class mapping. Can this be done using Criteria or HQL? I tried specifing order-by on the set in the FileType but that failed. It is mapped as a many-to-many, from FileType ...

26. Sorted many-to-many set?    forum.hibernate.org

27. How to get Hibernate to manage a sort order...    forum.hibernate.org

Using: Hibernate v2.1 I have a class, X, whose objects maintain lists of child objects of the same type, X (x1.getChildren() returns List[x2, x3, ..., xn]). I have hibernate set up to maintain the sort order for the children (via the sub-element to the ). However, since I obtain the top level X's via a query, Hibernate does not maintain ...

28. How to do this sort?    forum.hibernate.org

Hi all , I have a table relationship as follow : cart <--- item I retrieve the cart by select cart, sum(cart.price) from foo.Cart cart join cart.item item So I would like to : 1) sort the retrieved item by sum(cart.price) and then cart.createDate 2) page it using setMaxResults(10) How could I do it most simply ? As I tried select ...

29. how to sort with two table?    forum.hibernate.org

30. just need a pointer - many-to-many (sort of)    forum.hibernate.org

public class Audit { public final static String CREATE = "Create"; public final static String UPDATE = "Update"; private String method; private Date dateOfAudit; private String recordType; private Long id; private String user; private Set auditables = new TreeSet(); public ...

31. What does natural sort sort on?    forum.hibernate.org

Hi all, I haved evaluated Hibernate as part of my master thesis and just have a question regarding natural sorting of collections. Consider the following (made up) scenario: In the book Hibernate in action its described that natural sort will use the compareTo() method of java.lang.String to sort the collection in memory. ...

32. Getting a sorted set back    forum.hibernate.org

Code: ...

33. difficulty with sorted set    forum.hibernate.org

import java.util.Comparator; import org.simplecart.shopcart.model.Persistent; /** * * @author Daniel Watrous */ public class PrimaryKeyComparator implements Comparator { public int compare(Object obj1, Object obj2) { int result; Persistent pobj1 = (Persistent) obj1; ...

34. Strange sorting same name column on many-to-one    forum.hibernate.org

35. Sorted Collections using java.util.Comparator    forum.hibernate.org

36. Many-to-Many Sorting.    forum.hibernate.org

I have a situation where I'm successfuly returning a many-to-many relationship using the xml below. The resulting "set" is apperently an unsorted HashSet. I'd like to perform a sort using a TreeSet/compareTo method for display/editing purposes, but cannot because hibernate complains because I will loose the reference to the ...

37. Sorting a SortedSet    forum.hibernate.org

Hibernate version: 2.1.8 I have a simple 1-N mapping which utilizes a SortedSet. Lets call the owning class A and the class whose instances belong to the SortedSet B. Class B implements Comparable and hence the relation is mapped with sort="natural". Also, class B has a "date" field which is used in the comparison. Everything works as expected apart from the ...

38. Collection Sorting    forum.hibernate.org

39. Sorting a many-to-many collection    forum.hibernate.org

I have a many to many collection like so: where claim_user_orgs is an association table, and just has 2 columns: claim_user_id and organization_id. I want the collection property "organizations" of the claim_user object to return the list of organizations sorted by organization_name, so I did this:

40. Help with sorting results    forum.hibernate.org

Hibernate version: 2.1 Mappings : I have two tables: product table with primary key ID column (and a bunch of other properties). Another table has price rates for products, it's a many-to-many relationship table with properties (product_id,price_type_id,price) It's mapped inside product hbm files as follows: ...

41. Multilingual sorting    forum.hibernate.org

Need help with Hibernate? Read this first: http://www.hibernate.org/ForumMailingli ... AskForHelp Hibernate version: 3.0.5 Mapping documents: Code: ...

42. Sorting / Ordering a many to one set    forum.hibernate.org

43. sort-by on set with many-to-many problem    forum.hibernate.org

...

44. sorting collections    forum.hibernate.org

Hibernate version:v3 Can one sort objects by associations. Here is what I would like to do: Person: name address Visited Countries: country name One to many relationship between person and visited countries. P1 visited --> {Italy, France} P2 visited --> {India, US, Canada} p3 visited --> {Canada} p4 visited --> {France} I would like to use HQL or Criteria APIs to ...

45. Sort problems after upgrade to Hibernate3    forum.hibernate.org

I am in the process of upgrading my application to Hibernate3 and things are going well with one exception. One of my sets is sorting in the wrong order. Here is the relevant .hbm snippet: Code: ...

46. Some sort of caching problem... I think.    forum.hibernate.org

Check if you have set the property true In that case the result of the query will be cached and you will not see the post inserted. If you don't have that property, or it is set to false, your resultset will not be cached and your problem is somewhere else.

47. need help about Sorted collections    forum.hibernate.org

I am new to hibernate. I am using JDK1.5, jboss-4.0.3SP1, and Eclipse SDK. I need to get a collection sorted. I have used order-by attribute to sort the collection Set users = application.getUsers(); This code works fine and gives me an orderd set when I run it in a JUnit testcase. But when it is deployed ...

48. How to Handle Blank When Sorting?    forum.hibernate.org

49. HELP with sorted/ordered Set please    forum.hibernate.org

Hi, I am well through a project and have now had to change my code to allow for sorted collections. I have a unidirectional mapping in my parent class (CertificateStatementTitle) that contains one or more of CertificateStatement. This has worked fine before but now I need to have this sorted I'm getting problems. I'd like to sort the CertificateStatements on a ...

50. sorting on a property which is a collection    forum.hibernate.org

Given the following model public class Service { private Long id; private String name; private List audiences; .... } public class Audience { private Long id; private String description; private Provider service; } a portion of the service.hbm.xml file: it is currently ordered by name, but i actually ...

51. Sort collection by col in 3rd table    forum.hibernate.org

Hibernate version: version 3.1.3 Name and version of the database you are using: 4.1.13-standard 3 tables, parent, child & priority parent -parentId -colA child -childId -colB -priorityId priority -priorityId -seq The mapping for parent, of course, contains a set element for the child. Quesion: Is there a way to tell Hibernate to use priority.seq for sorting the children? I am using ...

52. Sort after adding object to a collection    forum.hibernate.org

Hi, I am adding an object to a child collection (Set) and then I save the object. For example: parent.getChilds().add(someChild); I want that the child collection will be sorted according to the "sort-by" property. Currently the object is added to the end of the list and only after opening a new session it is sorted properly. How this can be accomplished ...

53. error sorting on a derived property using criteria api    forum.hibernate.org

I am using the element to derive a property (which has no db column) and then I am trying to sort on this derived property using the criteria api and I get an exception. If instead I try to sort on a property that's not derived (ie maps to a column), it works. my derived property is defined as follows: ...

54. sort problem in hibernate 2.0    forum.hibernate.org

In my project, I used Hibernate2.0 with struts framework. In hibernate2.0, I used to get the records by using Criteria. Now I have a problem in sorting. For example, private abstract class Book { Integer bookId; String bookName; } private abstract class customer { Integer customerId; String customerName; Book cusomerBookId; } In this example,if I want to sort by customerId,customerName, I ...

55. Trouble initializing sorted set from second level cache    forum.hibernate.org

I'm having trouble initializing a (non-lazy) sorted set when the second level cache is enabled. I have a User object that contains a SortedSet of EmailAccount objects. When accessing the user, with the second level cache enabled, the set appears to be in the incorrect order. The EmailAccount objects implement Comparable by comparing creation timestamps. Using some debugging, the following sequence ...

56. Sort Hibernate Criteria Query Results??    forum.hibernate.org

I have Profile class that has two fields Person, Status. class Profile{ private Person person; private Status status; } class Person { private String firstName; private String lastName; } class Status{ private String status; } My requirement is to sort the results of Profile on Person.lastName. I am able to sort them on Person or Status. I have done on Status. ...

57. help me to sort this out    forum.hibernate.org

Caused by: org.hibernate.MappingException: Could not configure datastore from file: /home/wishwa/Desktop/SVN_03-12-07/vas_voting/trunk/dbtier/src/dev/hsenidmobile/vas/mvoting/dbtier/dao/hibernate/Competition.hbm.xml at org.hibernate.cfg.Configuration.addFile(Configuration.java:231) at org.hibernate.tool.hbm2ddl.SchemaExportTask.getConfiguration(SchemaExportTask.java:195) at org.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:135) ... 16 more Caused by: org.hibernate.MappingException: class hsenidmobile.vas.mvoting.core.model.Competition not found while looking for property: competitionKeyword at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:81) at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:275) at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:1798) at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:1787) at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:317) at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:235) at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:151) at org.hibernate.cfg.Configuration.add(Configuration.java:360) at org.hibernate.cfg.Configuration.addFile(Configuration.java:226) ... 18 more

59. Sorting sets using order-by    forum.hibernate.org

I'm trying to use order-by sorting to create a SortedSet, but I'm getting IllegalArgumentExceptions, saying that my set is of type PersistentSet, not SortedSet. Using sort="natural" works fine, but I can't get it to work using "order-by". The following is the stack trace for setting a set, but I also get errors loading a set if it's already in the database. ...

60. hibernate Sorting    forum.hibernate.org

61. Manual sorting of a collection    forum.hibernate.org

62. Sort with a Calculated Method    forum.hibernate.org

public class Media { .... private Set votes = new HashSet(); ... public int getEtoiles() { int total = 0; for (Iterator iterator = votes.iterator(); iterator.hasNext();) { Vote vote = (Vote) iterator.next(); ...

63. Sorting    forum.hibernate.org

Hi All, I am having problem in sorting the list in numeric order rather than alphabetic order for an integer column. In the mapping, I am using order-by attribute in set. I am able to order in alphabetic order like I-1 I-10 I-11 I-12 I-2 I-3 but my requirement is I-1 I-2 I-3 I-10 I-11 I-12 Please any body help me. ...

64. Sorting "sub" criteria    forum.hibernate.org

An Order object is created by using one of the two static methods in the Order class, namely the static asc(String) and desc(String) methods. Basically, you just chose whether you want your list to be sorted in ascending order, or descending order, and pass to the appropriate method the name of the field on which you want to sort. Order order ...

65. criteria and sort    forum.hibernate.org

Hi, I would like to know if it's possible to sort a result from a criteria based on many to many relation (and normal column) like I've an Affaire entity that contain representants and I would like to sort (or order I think it's similar) like this way Criteria.addOrder("participants.name") Thanks in advance

66. Prevent Update after sort...    forum.hibernate.org

Hi all, First, If this question has been answered, then quick guidance on where I could find the answer would be awesome! I checked, but maybe how i searched yielded no results. Basically: We have a view that allows us to go in depth on a resultset. At one point, we can sort an inner set. However, the problem seems to ...

67. How to sort a query by a property of an object in a Set    forum.hibernate.org

Hibernate version:3.1 I am trying to execute HQL, so that the results are ordered by a property of an object in a set. The object model looks like this: Ad contains ContentFile contains a set of ContentFileDetails where ContentFileDetails has a property called size. I want to order the query by the size property. my HQL ends up looking like this ...

68. Hibernate: Sorting objects based on FK    forums.oracle.com