element « Query « JPA Q&A





1. How to construct a hibernate query that uses a single element of all elements in a collection?    stackoverflow.com

Here's the situation: I have a datatype C that has a one-to-many reference to Datatype P. Datatype P has an optional R reference (one to one). My attempted query was as follows (it was ...

2. JPA 2 + Criteria API + get oldest element in subquery    stackoverflow.com

I have two entities (Dataset and Item), where the first one contains a list of the latter one.

@Entity
class Dataset {
    @Id long id;
    List<Item> items;
}

@Entity
class ...

3. Count Elements Conditionally In HQL    stackoverflow.com

I have an HQL query that returns projections of an entity including a count of the a certain child collection.

select t.Id as TagId, t.Name as Name, count(elements(t.Documents)) as Count ...

4. Hibernate SET element order-by clause    stackoverflow.com

I was wondering, I can find my peace with the fact that you can set the order-by attribute on a SET element in the mappings file when fetch=select, but if you ...

5. Is calling elements(?) on a selected set possible?    stackoverflow.com

I have two entities which they have a many-to-many relationship. E.g. AEnt and BEnt:

class AEnt {
    //....
    String name;
    Set<BEnt> bs;
 }

class ...

6. Repeating and missing elements when applying sorting and paging to a criteria    stackoverflow.com

I have a collection of entities, which I want to sort by one of the entity attributes (numViews). I use Criteria to create the queries. It is very simple and straightforward.

inputCriteria.addOrder(Order.desc((String) ...

7. elements() inside select?    forum.hibernate.org

Hi. I have 3 entities: Teacher, Cours, Room. The relationship Teacher-Cours is 1:n and the relationship Cours-Room is m:n Now I need to update all the Rooms where there is at least a Cours owned by a certain Teacher. I'd need something like 'Update Room r set r.valid = true where r in (select elements(cours.rooms) from Cours cours where cours.teacher= :teacher) ...

8. How to write Criteria like elements in hql    forum.hibernate.org

Hi, I have a mapping like the following: As shown above, class C has a map of elements of E. I can use the following hql to search for instances of C which ...

9. How to sort the elements within the set of a fetched object?    forum.hibernate.org

Good Morning, Comrades, I have got a criteria that fetches a unique result (StaffShortInbox) inside which there is a set of posts (Post). I am trying to order the set inside the unique result by one of the properties (order by Post.posted). Consider the following classes: StaffShortInbox Fields: Long staffId; String firstName; String surname; Set posts = new HashSet(0); //contains a ...





10. select element() as does not work    forum.hibernate.org

11. JPA 2 + Criteria API + get oldest element in subquery    forum.hibernate.org

SELECT d.id FROM Dataset d WHERE EXISTS ( SELECT TOP 1 * FROM Item i WHERE i.dataset_id = d.FALL_ID AND i.someCriteria = 'x' ORDER BY i.date ) ORDER BY d.FALL_ID

12. How do I find new elements in PostCollectionUpdateEvent    forum.hibernate.org

Short of comparing the new collection state from the snapshot by nested iteration (really bad for large collections) is there a more efficient way to find the new elements added to a collection in the onPostUpdateCollection method? For deleted elements I'm using the getOrphans call on the collection which also requires the snapshot. How efficient in general are collection updates? Does ...

13. Select not all elements of collection    forum.hibernate.org

I have 2 classes Organization and CompanyProperty. from Organization.xbm.xml : Code:

14. "Elements" & "Order by" clause    forum.hibernate.org

queryString = "select listeStat from StatistiquePersistent as listeStat " + "and listeStat.typeStat.libelleTypeStatistique <> :typeStatJournalier " + ...

16. Quick HQL query regarding elements    forum.hibernate.org

David, Yep, I did solve it, but I ended up using standard SQL. In this instance, I'm selecting all parts that are not associated with an assembly. From the assembly object, you can call getParts() to retrieve the association records. I never did figure out how to get at assemblies from the Part. Anyway, here is the query I used. Code: ...





17. Using collection elements in the where clause    forum.hibernate.org

Hello, If I have 2 classes Code: Owner { Integer id ; Set Pets ... } and Pet { Integer id ; ...

18. Query elements question    forum.hibernate.org

19. select distinct elements(...)    forum.hibernate.org

20. Using a delete query to delete elements of a collection    forum.hibernate.org

I'm wondering if it's possible to delete elements of a collection using a delete query. To be specific I have a User mapping a Content mapping and a many-to-many property called favourites that maps between the two. I want to delete all favourites that match a particular condition. Is this possible using a session.delete() query or do I have to manually ...

21. Ordering a collection acquired with HQL select elements(c)    forum.hibernate.org

Author Message adcworks Post subject: Ordering a collection acquired with HQL select elements(c) Posted: Mon Aug 16, 2004 7:12 am Senior Joined: Fri Jun 18, 2004 10:17 am Posts: 140 Hey all. I have posted a couple of posts on my set ordering not working and digging around discovered this was as I was using Set instead of SortedSet, ...

22. Order by element of Collection    forum.hibernate.org

23. exists, elements and subqueries    forum.hibernate.org

Hi, i need to perform an exists with a subquery, but i read in a previous post http://forum.hibernate.org/viewtopic.php?t=930043&highlight=elements+subquery that elements only applies to collections. The SQL query to translate is below, all my entities are mapped in hibernate as you would expect and are working fine. I use bags for all collections. Code: select distinct a.* from workflow_alarm a, ...

24. Trouble with select cat, count(elements( cat.kittens )) ...    forum.hibernate.org

select addressdom0_.POID as POID, addressdom0_.name as name, addressdom0_.createdDate as createdD3_, addressdom0_.createdBy as createdBy, addressdom0_.modifiedDate as modified5_, addressdom0_.modifiedBy as modifiedBy, addressdom0_.POID as x0_0_, count(addresses1_.POID) as x1_0_ from SAV.AddressDomain addressdom0_, SAV.UserAddress addresses1_ where addressdom0_.POID=addresses1_.domPOID group by addressdom0_.POID

25. hibernate query return some elements twice    forum.hibernate.org

I think it is a problem from my equals and hashCode method ... I can't see the problem.. Here are the 2 methd of my class public boolean equals(Object other) { if (this == other) return true; if (!(other instanceof RegionDropDownAbstract)) return false; final RegionDropDownAbstract reference = (RegionDropDownAbstract) other; if (!regionCode.equals(reference.getRegionCode())) return false; if (!countryCode.equals(reference.getRegionCode())) return false; return true; } public ...

27. Query collection elements    forum.hibernate.org

Hi! How can I query collection elements? What I mean by that is that persistent object has a property (collections) which holds other (same type) objects. I want to query those objects. I've written the query select elements(p.Friends) as friends from Person p where friends.Name like '" + searchPattern + "'" and this produces an error " , expected in SELECT". ...

28. Referenced query to same collection element    forum.hibernate.org

29. HQL Query for groups containing ONLY elements of a given set    forum.hibernate.org

Hi, I need a special HQL Query and I do not find a way to formulate it. I'm using Hibernate with MySQL. A group has many elements, and an element may belong to many groups. Group <-(1,n)---(1,n)-> Element Now, I'm searching those groups for a given set of elements which contain EXCLUSIVELY elements which are in the given set. In order ...

30. one-to-many with query: isEmpty or element.property is equal    forum.hibernate.org

Hello, I have simple set of elements. Person { Set events; } Event { Person person; String description; } I need to do simple query: Criteria criteria = sesison.createCriteria(Person.class); criteria.createAlias("events", "event"); criteria.add(Restrictions.or(Restrictions.isEmpty("events"), Restrictions.eq("event.description", "test"))); criteria.list(); With this line: criteria.createAlias("events", "event"); result is always empty (list size is zero). What do I do wrong? Isn't it possible to have this OR condition? ...

31. need query help; subqueries with collections, elements()?    forum.hibernate.org

I do not understand the use of the elements hsql key word. I am trying to form a query that compares to sets of data to see if there is a match: I have a person which has groups and I have a user which has groups. The groups can either be active or inactive. I am trying to query for ...

32. uncanny deleting some element from sorted collection    forum.hibernate.org

Hi, I have mapped some class with Set collection. It is mapped as one-to-many like: [b] [b] Class Photo contains variable "sorter" and implements Comparable where it is compared "sorter" value. I have noticed when I added next two and more instances of Photo class and call saveOrUpdate() usually ...

33. query for set of element types    forum.hibernate.org

[quote="igorarbizu"]Hello, I can't find how to build an hibernate query for a mapping like this in the docuementation: [b] [/b] I need to know all the existing person_names( select person_name from person_names, of course), but usin hsql, that is , without tables. [b]getSession().createQuery("select names from person").list()[/b] throws an error sayig names is not an ...

34. Querying by Scalar Collection Element?    forum.hibernate.org

...

35. WHERE clause in Set element of hibernate...    forum.hibernate.org

Hibernate version: 3.1 I am tring to use a set in one of my hibernate mappings that has a WHERE Clause in it. The clause needs to reference a table to grab the maximum date of a column. I am also working with a particular schema (default_schema in the hibernate config file), and I was wondering how to get at the ...

37. how do I select collection elements via criteria queries?    forum.hibernate.org

List results = session.createCriteria(Domestic.class, "cat") .createAlias("kittens", "kit") .setProjection( Projections.projectionList() .add( Projections.property("cat.name"), "catName" ) .add( Projections.property("kit.name"), "kitName" ) ) .addOrder( Order.asc("catName") ) .addOrder( Order.asc("kitName") ) ...

38. selecting "in elements(...)" as part of an HQL que    forum.hibernate.org

Hi all, I'm writing (what I think should be) a simple query, to select a number of items, as well as a boolean value of whether they occur in a collection. I have two classes, User, and NewsItem, where User contains a many-to-many collection called readItems. I wrote the following HQL query: select n, (n in elements(u.readItems)) from NewsItem n, User ...

39. Stucked with elements and group by clause    forum.hibernate.org

40. Online DTD broken on sql-query ELEMENT    forum.hibernate.org

41. with-clause referenced two different from-clause elements:    forum.hibernate.org

select new com.wsi.mm.model.directship.vo.ItemDirectShipSearchResultVO (item.id, item.description, item.style.id, directShipItemAttribute ) from ItemImpl item join item.department department ...

42. Query A View Returned A Collection with Null Elements    forum.hibernate.org

Hi, I am using Hibenate 3. I have a very simple view in a Oracle database. As I queried the view, I've got a collection with the right size but null element. For instance, if the query is meant to return 50 rows, the collection has a size of 50 but each element is NULL. Thank you so much in advance ...

43. How to query join table collection elements?    forum.hibernate.org

I have an entity object A that has a many-to-one relationship with object B with A having a list of collectionelement join-table C object and C object has a reference back to its parent (A and a many-to-one reference to entity B. My question is how do I generate a query to get A.user or A.list given a primary key id? ...

45. Quering Collection of elements with a Named Query    forum.hibernate.org

@Entity @Table(name="CUSTOMERS") public class Customer implements ICustomer{ .. id and other columns... @org.hibernate.annotations.CollectionOfElements(fetch=FetchType.LAZY, targetElement=Address.class) @JoinTable( name = "ADDRESSES", joinColumns = @JoinColumn(name = "customer_id") ) private ...

46. order by with select distinct elements()    forum.hibernate.org

Hi, my entity ContentItem has a List tags which is stored in her own table. Now I want a list of all available tags, therefore I use the HQL query: SELECT DISTINCT elements(tags) FROM ContentItem which works fine. But now I want this list to be literally sorted by tag which is a String SELECT DISTINCT elements(tags) as singeTag FROM ContentItem ...