criteria « Query « JPA Q&A





1. How do you "OR" criteria together when using a criteria query with hibernate?    stackoverflow.com

I'm trying to do a basic "OR" on three fields using a hibernate criteria query. Example

class Whatever{
 string name;
 string address;
 string phoneNumber;
}
I'd like to build a criteria query where my search ...

2. EasyMock and Hibernate Criteria Queries    stackoverflow.com

I am trying to test a dao method which uses the hibernate criteria API, using JUnit4 and EasyMock 2.4. When I run the test fixture 'testGetAsset' I receive the following exception:

java.lang.AssertionError: ...

3. Criteria queries in JPA    stackoverflow.com

Is there Hibernate criteria like queries in JPA?

4. simplest criteria query    stackoverflow.com

What is the simplest hibernate criteria query equivalent of

SELECT name FROM people WHERE id='3'
is it :
criteria.add(Expression.eq("id", 3));
and how can I retrieve it to String variable the value of name field, ...

5. Hibernate criteria query    stackoverflow.com

I am trying to execute a subquery using Hibernate criteria api but not been able to figure out completely how to go about it. Assuming there are 2 tables, SHOPS and ...

6. Hibernate Query Not Projecting Correctly in One To Many    stackoverflow.com

I am doing a query where I need to get a user back, that also has UserConnectors populated with it. My Query keeps bringing back two results instead of one ...

7. hibernate criteria query    stackoverflow.com

I have the following query sql query:

select * from Articles ar
left join ArticleTeamRelationships atr on atr.ArticleId = ar.ArticleId
left join Team te on te.TeamId = atr.TeamId 
inner join ArticleCategoryRelationships acr on acr.ArticleId ...

8. Sources to learn HQL and Hibernate criteria query    stackoverflow.com

I am completely new to hibernate and want to learn HQL ... I know basic MySql and want to relate Hibernate query with Mysql query Can some one please direct me ...

9. Hibernate Criteria Query not working properly    coderanch.com

Hi, Criteria query restrictions are not applied in the items of the collections. I have a persistence entity (POJO) Menugroup and it has a collection called catgroups (HashSet, one to many). Catgroup persistence entity (POJO) has another one-to-many collection "dealitems" (HashSet). My criteria query is below: code: List menuGroups = session.createCriteria(Menugroup.class) .add( Restrictions.eq("published", true)).addOrder( Property.forName("name").asc()).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY). setFetchMode("catgroups", FetchMode.JOIN). createCriteria("catgroups").addOrder( Property.forName("name").asc()). add( Restrictions.eq("published", ...





10. Hibernate HQL: Query to Criteria    coderanch.com

How can I convert this HQL to a criteria query? from User u where u in (select u2p.user from User2Application u2p where u2p.application.applicationId = :appId) There are 3 tables: User, Application, and User2Application. User2Application is a bridge table and contains an Application object, and User object. I am trying to retrieve all users who have access to the given application. The ...

11. Probelm with Hibernate Criteria Query    coderanch.com

Hi, I am unable to retrieve the data for this particular criteria query. public AM_ENDORSEMENT_XREF retrieveEndorsementByStatus(String ePolicyNumber, String status, String flag) { if (Logger.isLoggable(Logger.INFO)) { Logger.info(CLASS_NAME, RETRIEVE_ENDORSEMENT_BY_STATUS, METHOD_START); } AM_ENDORSEMENT_XREF amEndorsementXref = new AM_ENDORSEMENT_XREF(); try { // Get the data from AM_ENDORSEMENT_XREF table amEndorsementXref = (AM_ENDORSEMENT_XREF) currentSession() .createSQLQuery("SELECT X.* FROM AM_ENDORSEMENT_XREF X, AM_REGISTER_STATUS R " + "WHERE X.EPOLICY_NUMBER = ? AND ...

13. HQL Query to Criteria?    coderanch.com

14. Criteria Queries    forum.hibernate.org

I have the following tables: ITEMS ITEM_ID PLANT_ID ITEM_NUMBER ITEM_MFG_PART_NUMBERS ITEM_ID PLANT_ID MANUFACTURER_ID MFG_PART_NUMBER MANUFACTURERS MANUFACTURER_ID MANUFACTURER_NAME From an entity point of view I have an Item, ItemMfgPartNumber, and Manufacturer objects where the Item contains a collection of ItemMfgPartNumber objects and these ItemMfgPartNumber objects contain a property to Manufacturer. I need to be able to retreive all Item objects where ITEM_NUMBER ...

15. How to write in Criteria Query    forum.hibernate.org

Hi, Please help me out to write the following in Criteria or Example Query :- StringBuilder SQLquery=new StringBuilder(); SQLquery.append(" select dbo.getSearchString(qr.id) as queryString,qr.resultCount as resultCount, qr.dateFound as dateFound from SolrQLog.QueryResult qr where dateFound >= ? and dateFound <= ? group by qr.id, resultCount, dateFound order by "); if(sortType == null){ SQLquery.append(" resultCount"); }else if(sortType.equalsIgnoreCase("Search String")){ SQLquery.append(" queryString"); }else if(sortType.equalsIgnoreCase("Date")){ SQLquery.append(" dateFound"); ...

16. Criteria Queries, how to reuse or clone them ?    forum.hibernate.org

I have successfully built an hibernate criteria query. A common use case, it to perform the search ( .list() ) but also get the count of maximal number of hits. Now, this is not an issue if you build the criteria twice. But that seems overly redundant. What if I wanted to do more than count? Do I have to rebuild ...





17. Criteria equivalent of a (simple) hql query    forum.hibernate.org

18. Query with criteria Hibernate    forum.hibernate.org

19. Criteria queries on Set proprties?    forum.hibernate.org

20. criteria queries    forum.hibernate.org

21. criteria queries    forum.hibernate.org

22. Criteria Query for executing multiple queries.    forum.hibernate.org

24. Hibernate Criteria Query    forum.hibernate.org

I am new to hibernate and I have a issue. I have a Query SQL (select max(col1,col2,col3...) from table name where pkid in (id1,id2,id3...) and then I need to extract the Max data from result. Means if 10 rows are returned I need the Max Value. I need to know how to write a hibernate query for that Any help is ...

25. Criteria Query not working for single quotes    forum.hibernate.org

ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: syntax error at or near "ahmedabad" Position: 74 ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/mapcms_ui].[mapcms] - Servlet.service() for servlet mapcms threw exception org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2231) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125) at org.hibernate.loader.Loader.list(Loader.java:2120) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:312) ...

26. Query by criteria - item must belong to multiple category    forum.hibernate.org

Hi, i have a followed many to many (example) association: ---------------- --------------------------- ---------------------- | ITEM | | ITEM_CATEGORY | | CATEGORY | ---------------- -------------------------- ---------------------- | item nb. 1 | | item nb.1 / cat nb.1 | | category nb. 1 | ---------------- -------------------------- ----------------------- | item nb. 2 | | item nb.1 / cat nb. 2 | | category nb. ...

27. Using Query/Criteria instead of SQLQuery for a view.    forum.hibernate.org

I am using an SQLQuery to load some entities from a view. The view is not mapped -- the entities are already mapped to another table. Here is my code: Code: public class SampleDAO extends DAO { ... @SuppressWarnings("unchecked") public List findByAlliance (Alliance alliance) { ...

28. Hibernate Criteria query    forum.hibernate.org

I have a Book table Book_primary_key | book_id | book type 1 1 fiction 2 1 tech 3 2 basic 4 1 alien If book _id has 100 of id's with '1' and and only 30 books of book_id '2' Can I write a Hibernate criteria query to limit id's 1 and 2 to 20 each i.e. twenty rows containing book_id ...

29. How to use Criteria for query    forum.hibernate.org

I'm using Hibernate 2.1.1. The mapping files were generated by Middlegen R3. ------------------ Mapping file ------------------ Documento Code: (*) City_Category_Relationship (*) <---------(1) Category Logically, a city falls into many categories, and a category may be assigned to many cities. Or, there is a many-to-many relationship between city and category. I am mapping this using what I call a ...

41. Mistake in documentation for Chapter 15. Criteria Queries?    forum.hibernate.org

In Java, arrays are treated like objects, but deep down they are just C-style arrays. They inherit from Object sure, but you can't extend them and they really don't have methods. You can think of them as implementing generics, only before it was actually posible in Java. As if there were an array class implemented as such: class Array ... So, ...

42. hibernate queries with criteria    forum.hibernate.org

I've a little problem using hibernate queries with the api criteria. For a class like public class Document{ private User owner; private String title; .......... } with the classe User public class User { private String name; ...... } with criteria queries i wondered if I can do something like this : Criteria criteria = session.createCriteria(Document.class); criteria.add(Expression.eq("owner.name", "fred")); criteria.list(); when I ...

43. Using criteria queries?    forum.hibernate.org

Author Message infectedrhythms Post subject: Using criteria queries? Posted: Tue Apr 19, 2005 10:42 pm Beginner Joined: Fri Dec 10, 2004 11:46 pm Posts: 37 Hi I have to persitant classes... 1- Artist 2- Principal The classes are linked by many-to-one using the "principal" column... Now I would like to get a list of top X artists only if ...

44. DEEP criteria queries    forum.hibernate.org

I have a fairly simple question. Using criteria queries how is it possible to query on more than one collection that an entity holds. For example, the mapping documents below show mappings for three entities: 1. Camper 2. School 3. Registration So we have a camper who can have one school and many registrations Now, how do we use criteria queries ...

45. Hibernate Criteria Queries    forum.hibernate.org

I really like the criteria-based "query-by-example" feature. I have studied the docs, and I would like to confirm its full power. Please help me with the following: 1. Is is possible to submit multiple "examples" and do an or/and/not between the examples in one criteria? 2. Can the examples include the associations? Ie. is it possible to provide an example "Organization->Employees" ...

46. Criteria and Query could implement the same interface    forum.hibernate.org

Hi all, I was wondering: since Criteria and Query share methods like setCacheable, setMaxResults, list etc, why arent they just implement the same interface for it? The signatures could be changed to return instances of that interface to keep allowing chaining of method calls. This occured to me because i had to create duplicate methods in my session EJBs; i usually ...

47. Firebird + criteria: could not execute query    forum.hibernate.org

Newbie Joined: Thu Jun 16, 2005 8:01 pm Posts: 14 Erm... how do you mean? Something like this? Code: List result = crit.add( Example.create(criteria) ).list(); into List result = session.createSQLQuery("select userName from User").addEntity("User",User.class).list(); The last option gives me the following error Quote: Exception in thread "AWT-EventQueue-0" org.hibernate.exception.GenericJDBCException: could not execute query I do not know how to solve this problem :( ...

48. Criteria query and Cartesian Product    forum.hibernate.org

I have a query that filters the data that certain user has access to. I use HQL to execute that query, but I'm interested in using Criteria API. The problem is that I can't figure out how to express that using Criteria Query because I need to execute a cartesian product between the data I want and the user entity. I ...

49. Escaping Quotes In A Criteria Query    forum.hibernate.org

Hibernate version: 2.1.7 Dialect: GenericDialect Hi All, I have come across a situation where I need some assitance. I have a Criteria query that is failing when apostrophe's are present. I am using a priopriatary flat file db. The JDBC driver that I am using wants a \ to escape apostrophe's in a string. I assume the the GenericDialect is either ...

51. Query by Criteria query taking a bit long    forum.hibernate.org

Newbie Joined: Mon Mar 21, 2005 12:52 pm Posts: 11 Location: Chicago, Il Howdy folks: I have one doozy of a query to perform. Everything pretty much works as expected except it takes a really long time for results to deserialize into POJO's. Its also worth noting that hibernate is being used in conjunction with the Spring framework in my application. ...

52. attaching Criteria to a query instantiation    forum.hibernate.org

Query query = session.getNamedQuery("fromJobQueueList"); query.setProperties(jql); session.createCriteria(jql.getClass()).setFetchMode("JobQueueSysins", FetchMode.JOIN);

53. Criteria Query    forum.hibernate.org

54. Criteria for for 'startswith' query?    forum.hibernate.org

Hello, I am trying to optimize a query that returns names from a table where the lastName starts with a certain letter. Currently, I am using the following: Criteria criteria = HibernateUtil.getSession().createCriteria(Contact.class) .createAlias("contactInfo", "c") .add(Expression.ilike("c.lastName", searchLetter + "%")) .addOrder(Order.asc("c.lastName")); return criteria.list(); which is working, but is slow. I have an index on the ContactInfo table on lastName column, which helps, but ...

55. Info about Criteria Query    forum.hibernate.org

Hi Guys, I am new to hibernate, so please excuse if this is a very elementary doubt. I tried searching on the net about this, without much success. In our application we are using the following criteria query. Session m_HibernateSession = HibernateUtil.currentSession(); Criteria m_SelectionCriteria = m_HibernateSession.createCriteria (nativeVO.class); m_SelectionCriteria.add(Expression.eq("_Mnemonic", p_LocationCode)); m_SelectionCriteria.add(Expression.sql("ROWNUM=1")); m_SelectionCriteria.addOrder(Order.desc("_LastModifiedDate")); m_Native = (nativeVO)m_SelectionCriteria.uniqueResult(); Note that the ROWNUM=1 criteria is added ...

57. Building Query Using Criteria    forum.hibernate.org

List cats = sess.createCriteria(DomesticCat.class) .createCriteria("kittens") .add( Restrictions.or( Restrictions.like("mother.name", "F%"), Restrictions.like("name", "F%") ) ) .addOrder(Order.asc("birthdate")) .list();

58. How to achieve this in criteria query?    forum.hibernate.org

59. HQL versus Criteria queries    forum.hibernate.org

Hibernate version: 3.1 In the document it's given that 11.4.3. Criteria queries HQL is extremely powerful but some developers prefer to build queries dynamically, using an object-oriented API, rather than building query strings. Can anybody compare these two approaches for retrieving data? Is there any overhead for using Criteria for simple queries instead of HQL? Please advise as currently we are ...

60. Can I write this query with Criteria or HQL??    forum.hibernate.org

61. Criteria Query    forum.hibernate.org

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

62. Criteria Query    forum.hibernate.org

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

63. Criteria Query    forum.hibernate.org

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

64. HQL and Criteria Queries    forum.hibernate.org

65. HQL and Criteria Queries    forum.hibernate.org

Criteria queries are best used where you do not know which query parameters will be selected. For example: if you had a list of books, you could provide a screen which allowed the user to search for a book by the author, ISBN, title, date published, publisher, etc. In HQL you would have to build a string containing the query. That ...

66. Hql and Criteria queries work differently for "Any Mapp    forum.hibernate.org

I am using version 3.2.0.c4 My issue is, for a field in class that is declared like Suppose we want to query subject type teacher in hql this works fine ".. where mSubject.class=3 ..." however with criteria queries this doesnt work ...

67. Query or Criteria: which one is preferred?    forum.hibernate.org

68. Outerjoins in Criteria queries    forum.hibernate.org

69. A query with an or in the criteria    forum.hibernate.org

Hi there, does anyone know how to write the following sql equivalent with the org.hibernate.Criteria api? select * from x where (name='john' and title='mr') or (position='executive' and opinion='conservative') I've been running this as two separate queries and I'm finding it too inefficient. I'd like to run them as a single query, can anyone help. Cheers, Sivan.

70. Criteria Query throws SQLGrammarException    forum.hibernate.org

Hi, I'm doing some Criteria query: Code: (List) getSession().createCriteria(Group.class) .addOrder( Order.asc("name") ) .list(); The SQL (HQL?) generated is the following, I think the last word "this_" isn't right, is it? Hibernate: select this_.id as id0_0_, this_.version as version0_0_, this_.name as name0_0_, this_.description as ...

71. Query vs Criteria    forum.hibernate.org

I was reading in the hibernate documentation about Query and Criteria but I couldn't find which is better for what the doc says that if you prefer to use object oriented method for querying db instead of building string query you can use Criteria I'm asking: which is better for what ? and which is faster for what ? and which ...

72. Criteria vs Query. When choosing which?    forum.hibernate.org

Hello folks, I'd like to know the advantages of using each of the following class hierarchies (and inside a hierarchy when/why using a certain member instead of another): 1) Query (SQLQuery, NamedQuery, AbstractQueryImpl, SQLQueryImpl) 2) Criteria (CriteriaImpl, CriteriaImpl.Subcriteria). Also is there a difference in term of performance when using a named query (defined in a mapping file: , and called ...

73. Criteria Query Not Working    forum.hibernate.org

Newbie Joined: Thu Jan 11, 2007 5:53 pm Posts: 3 Hi, I'm developing an application using Spring 2 + JPA + Hibernate, and I got some problem trying to create a 'find' method for a Generic DAO using the Criteria API. Here are the codes: applicationContext.xml Code:

74. criteria query    forum.hibernate.org

75. hql query to criteria query    forum.hibernate.org

Hi all, Im having some problems with the left join in the criteria query. Im trying to join 2 tables by a left join, but I want two restrictions in the join: I want to get a sql query like this: "select * from items1 left join items2 (on items1.id = items2.items1_id and items2.property = 1) " I know how to ...

76. Disjunction query with multiple criteria    forum.hibernate.org

77. Using criteria and hql in the same query    forum.hibernate.org

78. Criteria/HQL queries    forum.hibernate.org

Is their any major difference with respect to Performance in using Criteria vs HQL based queries? I am considering Criteria based queries for my project as I faced issues to get HQL working fine. I posted this already in forum but didn't get any hint so far. When I used HQL I am getting SessionFactory as null sometimes not always. In ...

79. Regrading criteria queries.    forum.hibernate.org

80. How to do Criteria based query with Read only?    forum.hibernate.org

We are currently writing an application that reads data from a source database, transforms it, and loads it into a target database. We are using Hibernate only for reading from the source database (Oracle 10g). I'm primarily concerned with increasing our reading speed. Here are a few characteristics of our app: * The Hibernate mappings were generated using Hibernate's reverse engineering ...

81. $30.00 offered for a criteria query solution.    forum.hibernate.org

I am willing to paypal $30.00 to whoever can come up with a nice simple criteria query in c# or java code block for the following (nhibernate mapping files below) The spec states the following: Quote: findQualifiers: This collection of findQualifier elements can be used to alter the default behavior of search functionality. FindQualifiers Quote: orLikeKeys: when a bag ...

82. Criteria Query    forum.hibernate.org

Hello, I want a small help in Criteria Queries. e.g. my database table is like following Primary-Key Column : Column-1 : Column-2 : .... : Column-N 1 : : 100 : ... : anydata 2 : 1 : 101 : ... : anydata 3 : : 100 : ... : anydata 4 : 2 : 101 : ... : anydata 5 ...

83. Multi query using criteria    forum.hibernate.org

I am writing a web app using hibernate java struts. I have a piece of code for a search bar that follows: List listofsome = session.createCriteria(some.class) .add(Restrictions.like("firstName", searchString+"%")).list(); this works but only searches for the string on one column of my database. My question is can i incorporate another line of code into this to query another column? or do i ...

84. HQL query -> Criteria query    forum.hibernate.org

85. Advice on a Criteria query needed, thanks.    forum.hibernate.org

select sr.id, r.date_created, sr.product_group, sr.territory, u.unitid, u.code, u.name, u.unit_typeid, u.countrytypeid, u.country, col.collectionid, col.code as col_code, col.name as col_name, col.componenttypeid as col_componenttypeid, cs.cstateid, cs.code as cs_code, cs.name as cs_name, cs.shortcode as cs_shortcode from req r inner join some_req sr on sr.id = r.id inner join req_collection rc on rc.id = r.id inner join collections col on col.collectionid = rc.collection_id inner join req_cstate ...

86. Query.setReadOnly() equivalent for Criteria?    forum.hibernate.org

87. Complete criteria query trouble    forum.hibernate.org

88. Newbie: How to use Criteria to Query this?    forum.hibernate.org

89. using criteria query    forum.hibernate.org

@SuppressWarnings("unchecked") protected List findByCriteria(Criterion... criterion) { Criteria crit = getSession().createCriteria(getPersistentClass()); for (Criterion c : criterion) { crit.add(c); ...

90. criteria query for items without bids    forum.hibernate.org

Items and Bids in my case have one to one mapping Bids have FK to Item I want to write a cretirea qurey to fetch all items with out bids Items 1 2 3 Bids PK Item_FK 10 1 2 4 2 I want criteria query which return me 3 row from item becasue it is not in Bids table , ...

91. simple criteria query    forum.hibernate.org

Hi, Following from the hibernate examples, let's say I have a list of Cats each containing a list of kittens with the date they were born (column "born" on kittens table) and their name. Let's say I want to query all Cats that have a kitten where I want to check that only the last Kitten born has a name equals ...

92. Query to Criteria    forum.hibernate.org

Hi! I need your help! I have this query and I need to do with Criteria: select ifnull(count(i.id),0) as num_incidencias, ti.id, ti.descripcion from tipos_incidencia ti left join incidencias i on i.id_tipo_incidencia = ti.id group by ti.descripcion order by num_incidencias desc I need to get all objects TipoIncidencia sorted by number of occurrences in Incidencias. Thanks a lot!!

93. Hql vs Criteria queries    forum.hibernate.org

94. Hql vs Criteria queries    forum.hibernate.org

95. Criteria Query to get the birthday    forum.hibernate.org

Dear All, I have to write a Criteria Query to get employee name and employee email from Employee table, where the birthday anniversary is today. So How to write the Restrictions Currently i have Criteria criteria = session.createCriteria(Employee.class); criteria.add(Restrictions.eq("this.EPMST_BRITH_DATE", today)); I know the above line is not correct, so please help me to write the query to compare only today day,month ...

96. Criteria query and many-to-many    forum.hibernate.org

99. How to create Criteria for the query: indirectly-related    forum.hibernate.org

Hello, I need some help to create criteria: 3 class ( tables): Book (title, Author) Author (name) Dept (name, Author) Book --> Author Dept --> Author public class Book { .... public Author getAuthor(); } public class Author { .... public String getName(); } public class Dept { public String getName(); public Author getAuthor(); } In our app, there is no ...