Questions tagged [hibernate-criteria]

The Criteria interface of Hibernate ORM , represents a query against a particular persistent class. The interface provides access to the powerful mechanism of hibernate criteria API, that allows the programmatic creation of queries against the DB.

Hibernate provides an alternate way of HQL to manipulate objects and it is called Hibernate Criteria Query. The Hibernate Session interface provides createCriteria() method which can be used to create a Criteria object. This criteria object returns instances of the persistence object's class when the application executes a criteria query.

The primary advantage of Criteria Query over HQL and native SQL is that it allows OOP control over the queries and hence it is more dynamic compared to HQL. In order to make HQL dynamic String concatenation needs to be done, which is not considered as a good programming concept.

To learn more about Criteria Query and it's usage the official website of Hibernate is a very good resource.

1659 questions
0
votes
0 answers

Create unmapped object from Hibernate Criteria query

Using regular HQL I was able to get Hibernate to return a List of an object unmapped to the database by doing something along the lines of List result = (List) session .createQuery("select new…
radar
  • 595
  • 2
  • 11
0
votes
2 answers

How to use createAlias for a null Set Attribute with Hibernate Criteria Api?

I have an entity Car that has a nullable set of vignettes , and i want to get the Car list that haven't a vignette. i tried with this but i don't find my way ... Criteria criteria =…
0
votes
1 answer

Simple Criteria query - Select From IN

I have table Events | EVENT_ID | OTHER | ---------------------------- | | | | | | | | | and table EventCategories that contains foreign key for Event table: | …
0
votes
1 answer

Putting the Criterions into List for 'OR' condition

I have the requirement where I need to use Criterion for or condition. This Criterion will be created in loop. So I am adding the Criterion into a List. And outside of the loop I am adding these Criterion's into Criteria and typecasting the…
Pradeep Kr Kaushal
  • 1,506
  • 1
  • 16
  • 29
0
votes
1 answer

Nested Query in Hibernate using Criterion

I have a following query where I have to select rows from temporary table created by subquery. select x, y, x from (select x, y, z from some_table where x between x1 and x2) where y like 'y1' order by z by desc I have to use Criteria for…
abhijeet
  • 849
  • 2
  • 19
  • 54
0
votes
1 answer

Java Persistence Criteria Predicate for OneToMany(DB ManyToMany) Relationship

I have this a very basic problem and i am sure that there is a very simple solution to it. I have two entities having many-to-many relationship at db level. Customer and Channel joined by Customer_Channel. I am not a very pro at java persistence…
0
votes
0 answers

Joining 3 tables with hIbernate criteria

Is there a way to write the following sql using hibernate criteria? select A.columnA1, B.columnB1, C.columnC1 from A inner join B on A.fk_id = B.id inner join C on C.fk_id = B.id This question is slightly different from Hibernate Criteria and…
maxhuang
  • 2,681
  • 1
  • 21
  • 26
0
votes
1 answer

How to use Subqueries.in

How to express such HQL query via criteria API? select a from A a where (select b.prop from B b where b.id = a.parent) in ('1', '2', '3') List of ids is passed as parameter. Here is my subquery: DetachedCriteria subQuery =…
SpyBot
  • 487
  • 2
  • 6
  • 16
0
votes
1 answer

Hibernate subcriteria with FetchMode doesn't work

I want to use criteria with some conditions of its one to many field. Introducing my model briefly, one item has multiple options. Because I want to get item with filtered options, and pass it to JSON Parser (with no session), I have to get…
crazy_rudy
  • 533
  • 2
  • 4
  • 19
0
votes
2 answers

Hibernate 4.3.5 DetachedCriteria not fetching lazy list

I have a simple query that worked for a good time, now i changed some stuff in my code to: (hibernate.cfg.xml) org.hibernate.transaction.JDBCTransactionFactory
Simego
  • 431
  • 5
  • 16
0
votes
1 answer

Hibernate call function with criteria

i'm new to hibernate. I want to call my custom function with criteria. Simply, i want to call function like this : SELECT * FROM table WHERE test=1 ORDER BY my_own_function(arg1, arg2) asc This problem may be solved by using HQL. But i have many…
crazy_rudy
  • 533
  • 2
  • 4
  • 19
0
votes
2 answers

Grails list() - handling Out of memory and restricting list results

I am facing following problems in Grails. Here is my code in which I am trying to get list of all possible data and display it. def c = Abc.createCriteria() def results = c.list(){ eq("A", "a") eq("B", "b") } As the results is huge it goes…
Amy PrIce
  • 47
  • 1
  • 7
0
votes
0 answers

Convert SQL to Hibernate Criteria

I'm a newbie with Hibernate so I have difficulties to convert my SQL requests. I have the following SQL request : SELECT product_name, sum(quantity) FROM final_product JOIN customer_order_entry ON final_product.final_product_id =…
user3561383
  • 77
  • 1
  • 13
0
votes
1 answer

"org.hibernate.PropertyNotFoundException: Could not find setter" for an associated object

I have the following method where I want a User object with a few fields i.e. name, address.country and a few more. I am trying to get the the country data in the list but cannot (only name data appears). public List getActiveUsers() { …
Vishal
  • 85
  • 3
  • 10
0
votes
1 answer

Hibernate criteria calculation of two columns

I have a class called task which is as: public class task { int id; Date dueDate; int treshold; } treshold is how much hour before dueDate user want to get notification in terms of hour. I created a quartz job which starts every hour…
bdogru
  • 812
  • 1
  • 11
  • 19
1 2 3
99
100