Example « Query « JPA Q&A





1. Hibernate Query By Example and Projections    stackoverflow.com

To make it short: hibernate doesn't support projections and query by example? I found this post: The code is this:

User usr = new User();
usr.setCity = 'TEST';
getCurrentSession().createCriteria(User.class)
.setProjection( Projections.distinct( Projections.projectionList()
.add( Projections.property("name"), "name")
.add( Projections.property("city"), "city")))
.add( ...

2. Where are the NHibernate/Hibernate HQL and ICriteria query examples?    stackoverflow.com

I'm still quite new to NHibernate and most of it I'm getting to grips with. One area that I'm really lacking a proper understanding of though is querying (at least ...

3. Example using countDistinct in a JPA Criteria API query    stackoverflow.com

I'm having trouble figuring out how to represent the following JPQL query:

SELECT count(e) FROM Foo e
using Criteria API. What I'm trying is:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Foo> c = cb.createQuery(Foo.class);
Root<Foo> f = c.from(Foo.class);
c.select(cb.count(f));
but ...

4. How to get over limitations of the Hibernate Criteria and Example APIs?    stackoverflow.com

I'm in a position where our company has a database search service that is highly configurable, for which it's very useful to configure queries in a programmatic fashion. The Criteria API ...

5. Implementing Query By Example functionality in JPA    stackoverflow.com

Do you know a way of implementing something like a Hibernate QBE (Query by Example) in JPA? For my problem domain the alternative of using it will be to build a ...

6. hibernate query by example alternatve    stackoverflow.com

We have recently implemented some query by example functionality for hibernate. This post is aimed at seeing if there is already existing hibernate functionality which provides this feature. As well as ...

7. Hibernate Query by Example    coderanch.com

Hi All, I'm stuck with a problem. I want to use Hibernate Query by Example but am getting a problem with my result. I'm querying over two tables, a parent-child situation. I have a class called CheckSum and a class called Record. CheckSum has a set of Record. When i execute the query, the resultset of CheckSum is equal to all ...

8. Problem in Query By Example (Hibernate)    coderanch.com

Hi I am using hibernate3 in my application. When executing the below code Product exampleProduct=new Product(); exampleProduct.setPrice(22); Example example=Example.create(exampleProduct); Criteria criteria=session.createCriteria(Product.class); criteria.add( example ); List results = criteria.list(); it works fine. Lists all the objects with the price is 22. when modified the code as below Product exampleProduct=new Product(); exampleProduct.setName("Product 2"); Example example=Example.create(exampleProduct); Criteria criteria=session.createCriteria(Product.class); criteria.add( example ); List results = ...

9. Problem with Hibernate Criteria, Query by Example and "nullable=false"    coderanch.com

Hi, i am using Hibernate Criteria with "Query by Example" and have some problems when i set "nullable=false" for OneToMany mapping inside my entities. The problem is, that the generated SQL query is not the one i expected. Here is my example code: Person.java: @Entity @Table(name="personen") public class Person { @Id private Integer bp_personenid; @OneToMany(fetch=FetchType.EAGER) @JoinColumn(name="bp_personenid", nullable=false) @Cascade({CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN}) private Set ...





10. Query By Example help    forum.hibernate.org

User user = new User() user.setUserId(userId); Example ex = Example.create(user); ex.ignoreCase(); ex.enableLike(MatchMode.ANYWHERE); list = getSession().createCriteria(User.class).add(ex).list();

11. Query by Example    forum.hibernate.org

Newbie Joined: Sun May 15, 2011 10:12 pm Posts: 1 Hi all We have recently implemented some query by example functionality for hibernate. This post is aimed at seeing if there is already existing hibernate functionality which provides this feature. now i realise that the following API exists Code: Example exampleUser = Example.create(u) .ignoreCase() .enableLike(MatchMode.ANYWHERE) .excludeProperty("password"); return getSession().createCriteria(User.class) .add(exampleUser) .list(); However ...

12. Question querying with Example in Many to One    forum.hibernate.org

Newbie Joined: Thu Oct 27, 2011 4:53 pm Posts: 1 Greetings! I'm wondering if anyone has any experience (or helpful tips) when attempting to use the Example implementation of Criterion to query a many-to-one by the "one" side. Logically, I have a Record (table/class) and a Transaction (table/class) where Transaction has a FK to Record's PK. In java, my Transaction class ...

13. Query By Example documentation?    forum.hibernate.org

Hi, with great interest I read that Hibernate now has an approach for QBE. That is wonderful. However I could not find it mentioned while searching the documentation or the Hibernate site (apart from the announcement in the news-section.) I only found a short example in the API doc for the Example class but that still leaves some questions open. Particularly ...

14. Query by Example    forum.hibernate.org

Hi, I'll try to be more precise. I use hibernate-2.1, with an Oracle 8i database. I did several tests, and here is what I can say. To open and close sessions, I use the class HibernateUtil given in the hibernate distrib. Here is the code, in a method where I pass a parameter value of type Object. List result = null; ...

15. Example simple join query    forum.hibernate.org

just having a bit of trouble with hsql syntax. I've read the other posts and I guess I'm stupid cos I still dont get it. Ideally i can use a prepared statement using session.find the problem is I've a joing table thats not a java object. I want to do this in a find method or query if i must select ...

16. Combining Query by Criteria and Quer by example    forum.hibernate.org

Hi, I am working on an application where most of the queries are complex and there where clause is dynamic based on the the search criteria. Some queries only involve equal comparison and i used query by example in that cases but in most of other cases other operators (>,<,Or,and) are used. In the second case i have to make a ...





17. Pagination Example    forum.hibernate.org

Hi, I have taken the time to read all the posts here on Pagination and trying to implement pagination. However, I have not seen one example of anyone coming out and saying "Hey ! I've done it in Hibernate and here is some pseudocode". I have read about setMaxResults() and setFirstPage(), but I am still not sure of how to get ...

18. Example queries help    forum.hibernate.org

Hi, I am hoping someone might be able to notice something that I am missing on a simple Example query. I have used http://www.hibernate.org/hib_docs/reference/en/html/querycriteria.html#querycriteria-examples as a reference to produce the following code: Code: ApbecEducationalCounselor ecdata = new ApbecEducationalCounselor(); ecdata.setAlumSeqNum(new Long(alumID)); ...

19. query by Example    forum.hibernate.org

Example queries "Version properties, identifiers and associations are ignored." What is than the best way to search by example when you have associations? For example: we have class Book which holds many-to-one Author object public class Book { private int m_book_id; private String m_title; private Author m_author; ... public Author getAuthor() { return m_author; } public void setAuthor(Author author) { m_author ...

20. Help with Criteria and Query by Example    forum.hibernate.org

Hibernate version:2.1.6 Hi, I'm trying to do a combination of Query by Example and some Expressions.. I have 4 classes: - Company (has a set of "Agencies") - Agency (has a component "Address") - Address (a component having a "Zipcode" object among others) - Zipcode What I need to do is, to recieve a Company object to use as example and ...

21. Query By Example and Or Logic    forum.hibernate.org

Here's my code: Example exampleClient = Example.create( client ) .ignoreCase() .enableLike( MatchMode.ANYWHERE ); If client.firstName has a value for 'Frank' and client.lastName has a value of 'Tyler' the resulting where clause generated by Hibernate is something like this: where (lower(this_1_.firstName) like ? and lower(this_1_.lastName) like ?) limit ? I would like a way to have the where clause generated as where ...

22. query by example doesn't work    forum.hibernate.org

Hibernate version:2-1 Mapping documents:

23. Many to Many query example    forum.hibernate.org

24. Query-by-Example with transient many-to-one    forum.hibernate.org

25. QBS or query by Example    forum.hibernate.org

26. Query By Example Single Column Support in SELECT?    forum.hibernate.org

Newbie Joined: Tue Apr 05, 2005 3:52 pm Posts: 2 Location: Minneapolis, MN Hi, I'm new to hibernate so please bear with me. My question is not exception/bug related but rather feature/functionality related. Specifically, I want to leverage the power of the QBE capabilities inherent within Hibernate...and yet not return the full collections of objects, but rather only a simple collection ...

27. Example queries respecting (selected) null values?    forum.hibernate.org

Kuwe wrote: So, I guess one cannot use an Example Query here?! Code: Group example = new Group(); example.setA("red"); example.setB("large"); example.setC(null); List result = session.createCriteria(Group.class) .add(Example.create(example) ...

28. Example query - bad result set    forum.hibernate.org

Newbie Joined: Tue Jul 26, 2005 10:12 am Posts: 4 Hello :) Hibernate version: 3.0.2 Mapping documents: Code:

29. Advanced Queries... need examples!    forum.hibernate.org

Can anyone point me to some examples of advanced hibernate queries? I have had many problems creating advanced queries, which do not seem to be covered in the reference manual. 1) I am trying to use the Criteria API to create the equivalent of: select * from item where classifier in (select classifier from classifier_parent where parent in (parentList)) I have ...

30. Criteria Query Example.    forum.hibernate.org

Need help with Hibernate? Read this first: http://www.hibernate.org/ForumMailingli ... AskForHelp Hi, Hibernate version:3.0.5 [b]Name and version of the database you are using: Oracle 10g Can anyone give me an example of a Criteria Query with an Integer value set on an instance of the Object we are selecting? To make it more clear, If i have a Class Example. // Create ...

31. Example of Query reordering    forum.hibernate.org

32. Query by Example creates an update statement    forum.hibernate.org

Newbie Joined: Thu Feb 17, 2005 3:01 pm Posts: 9 Query by Example is causing the object to be updated . Any help would be appreciated Thanks murparth Hibernate version: Hibernate Version : 3.00 ConCalcDetail object has a set of ConCalcSchedules. We are using session per Request pattern. Mapping documents: ...

33. [Criteria Query] Many examples    forum.hibernate.org

for(Iterator i=st.getAccountSet().iterator();i.hasNext();) { Example ex = Example.create((Account)i.next()).ignoreCase().enableLike(MatchMode.ANYWHERE); ...

34. Criteria Query, using 2 example queries, howto?    forum.hibernate.org

Hibernate version: 3.1 Full stack trace of any exception that occurs: ClassCastException Name and version of the database you are using: Oracle 10g Hi there, I am having a hard time with the following problem, if anyone could help me, I'd be quite happy. I have the following relations: A Matter has o..n roles, a role has 0...n parties. So in ...

35. Query by example does not read not null object    forum.hibernate.org

import_file_id_seq ...

36. Combining Projections and Query by Example question    forum.hibernate.org

Hibernate version:3.1 I am having a problem trying to do a Criteria query by example as follows... Code: public List findByExample2(SfaAccountsSearchV instance) { return getCurrentSession().createCriteria( SfaAccountsSearchV.class) .setProjection( Projections.distinct( Projections.projectionList() ...

37. Problem doing Query By Example    forum.hibernate.org

Hibernate version:3.1.2 cr2 Hi, I just want to ask that does Query by Example supports associations or not. e.g. If i have bi-dircetional one to many relationship in Department and Employee domain objects and i want to use query by example for Employee object and then set DepartmentModel in it with department id given then will i be returned list of ...

38. Query by Example Problem    forum.hibernate.org

private String id; //PK private Date createddate; private String updatedby; private Date updateddate; private char deleted; //Init my Bean Object rates = new Object(); rates.id("2"); ...

39. Criteria Example query with projection    forum.hibernate.org

Hello, I am trying to use criteria query using example and trying to resolve this since last few days. I need to use projection with the example query to get only certain properties - I am trying following, but it is not working. User usr = new User(); usr.setCity = 'TEST'; getCurrentSession().createCriteria(User.class) .setProjection( Projections.distinct( Projections.projectionList() .add( Projections.property("name"), "name") .add( Projections.property("city"), "city"))) ...

40. count(*) for example query    forum.hibernate.org

41. find by example    forum.hibernate.org

42. Need Help in Query By Example    forum.hibernate.org

Hi All I'm new in this Hibernate world. As usual, I'm facing a problem. In my query example, I've a table with composite id. This table is mapped to one class having inner class. this inner class is mapped with composite id. To use QBE, i create an instance with some id. and then i pass this instance to use as ...

43. problem in find by example    forum.hibernate.org

org.springframework.orm.hibernate3.HibernateQueryException: Expected positional parameter count: 1, actual parameters: [[com.company.package.model.businessobject.childTable@47b708]] [from MasterTable where childTableSet like ? ]; nested exception is org.hibernate.QueryException: Expected positional parameter count: 1, actual parameters: [[com.sierra.intranet.model.businessobject.SaEmployeeLeaveStatus@47b708]] [from SaLeaveCategoryMaster where saEmployeeLeaveStatusSet like ? ] Caused by: org.hibernate.QueryException: Expected positional parameter count: 1, actual parameters: [[com.sierra.intranet.model.businessobject.SaEmployeeLeaveStatus@47b708]] [from SaLeaveCategoryMaster where saEmployeeLeaveStatusSet like ? ] at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:319) ...

45. query by example question    forum.hibernate.org

Hi, I want to do a query by Example...My example would be a Question. So i pass a Question and i want to get a list of all the same question which i have stored in the DB. My question Object is defined as follow.It has a collection of possible answers as well as a text property. ----------------------- Question{ Set possibleAnswers; ...

46. Hibernate Query by Example problem    forum.hibernate.org

47. Problem with Query By Example on a SQL Server    forum.hibernate.org

Hiya, I have aproblem witha QueryByExample not doing what I expect, and I want to see the actual SQL query that's being sent. But it doesn;t turn up in any log I try (log4j). It's to a SQL Server database - anyone have any clue how I can see the query? Cheers Tracey

48. Query by Example - object as property of example object    forum.hibernate.org

Hi Girls and Boys, I wasn't able to find what I needed in Documentation (nor could Google), so I decided to post here. I am trying to build a search for a small j2ee application, and I decided to give Query by Example feature a chance. In the documentation is described that you can set a property of an Example object, ...

49. Exception when using query by Example with Oracle CLOB    forum.hibernate.org

Hi, I am trying to use query by example on a class with a clob field, but I get an 'SQlGrammarException: inconsistent datatypes: expected - got CLOB' when I call criteria.uniqueResult();. I attached a small Testcase and the received Exception below. Hibernate version: 3.2.6 Mapping documents: Code:

50. Criteria with query by example does not work    forum.hibernate.org

public List listaCierres(CalendarioCierres calendarioCierres, CalendarioCierresPK cierresPK){ Criteria c = sessionBA.createCriteria(CalendarioCierres.class); calendarioCierres.setPk(cierresPK); Example example = Example.create(calendarioCierres); example = example.enableLike(MatchMode.ANYWHERE); example = example.ignoreCase(); c.add(example); ...