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
4
votes
2 answers

Does the Java/Hibernate Criteria Query API Protect Against Injection?

This might be a dumb question, but I have not seen anything in the docs explicitly stating that criteria queries are parameterized or otherwise injection-protected under the hood. In other words, is a predicate like the following directly vulnerable…
4
votes
1 answer

Is there a way to (locally) bypass or disable an AttributeConverter during a Criteria API call?

Suppose a CreditcardNumb.class with a constructor that checks if the credit-card number is valid. I then create a CreditcardNumbConverter.class to convert credit-card numbers to Strings in the database: public class CreditcardnumbConverter …
Marcelo Glasberg
  • 29,013
  • 23
  • 109
  • 133
4
votes
2 answers

Fetch the children of a lazy one to many list

Context : Development of in-house web applications using play framework (1.3), hibernate (4.3.8) and some Groovy on the html side. I'm currently working with Hibernate and I was assigned to find some optimization techniques. We have some loading…
Tapaka
  • 367
  • 4
  • 17
4
votes
4 answers

Is it possible to use aggregate functions and property in Projections, Criteria, Grails?

I am using Grails Criteria (similar to hibernate criteria) to get a list of Student who got highest grade in each division from the given table. And I want ONLY Name, Division and Grade fields. Name | Division | Grade |…
4
votes
1 answer

How to join two tables using JPA Criteria Builder?

I have an sql table called school, and another called student. Every school has an ID, and every student has a "school ID", which is the ID of the school they belong to. Now I want to find all schools in which there is a student called "John". The…
4
votes
0 answers

How should one use Where-Queries and DetachedCriteria in Grails?

EDIT1: I also accept answers that guide me in reusing DetachedCriteria without where queries. Where queries are my preference, but if regular DetachedCriteria is less hassle and more mature, I am willing to use it instead. I've been trying to wrap…
4
votes
3 answers

Hibernate Criteria Projection

Well as the question title says, I am trying to make a projection criteria querying only couple of the table attributes. So I have a Person Table/class and it has about 40 attributes. I want my criteria to get dynamical number of attributes, lets…
Darwly
  • 344
  • 1
  • 6
  • 22
4
votes
1 answer

Hibernate One-to-Many relationship cascade delete

I am new to Hibernate so please guide me. I have 2 entities Companies & Employees. One Company should have many employees. Employees Hibernate Mapping File
4
votes
2 answers

How to use Oracle query hint in Hibernate

I am trying to use Oracle hint in Hibernate to call force index, but didn't find any proper API in Hibernate 3.6.10.Final. I somehow tried with projections in Hibernate criteria: proList.add(Projections.sqlProjection("/*+…
Santosh
  • 362
  • 4
  • 15
4
votes
1 answer

NHibernate and C#: error using nested properties with Criteria

The scenario is a MVC.NET application using NHibernate to interact with a SQL Server database. Every NHibernate query with Criteria works fine, except for the last I have added, that give the following error: could not resolve property:…
UnclePetros
  • 185
  • 10
4
votes
1 answer

Hibernate Criteria could not resolve property when it's there

This one has me stumped. I have an idea how criteria works but for some reason this query is giving me issues not being able to find a property when it's clearly there. Shelf.java @Entity @Table(name="BOOKSHELF") public class Shelf { @Id private…
SS113
  • 548
  • 1
  • 11
  • 21
4
votes
1 answer

is it possible to maintain the different schema in same entity class

I have two schema(claim and policy). For both schema am using same Entity class. My problem is, claim schema has column city but policy schema does have city column. So If I use entity class by policy schema I get error. is this only the way to…
KSK
  • 636
  • 1
  • 9
  • 29
4
votes
1 answer

Is Hibernate Criteria API Deprecated and if so what API should we use?

Just as the title says. Is it deprecated? It says in the dev manual that it is and we should user JPA Criteria, but in the user manual there is no mention of this.
alambrache
  • 108
  • 1
  • 9
4
votes
0 answers

Hibernate Criteria ResultTransformer - bean with List / Set inside

I have entity like this: public class EntityClass{ private String id; private String name; private List others; } and bean class like this: public class BeanClass{ private String id; private String name; …
4
votes
2 answers

Using Hibernate's Criteria API, can I use concat with ilike restrictions?

Intuitively, what I want to do is something like this: Restrictions.ilike("concat(user.firstName, ' ', user.lastName)", text.toLowerCase() + "%") However, I know that this won't work, because concat(user.firstName, ' ', user.lastName) is not a…
egervari
  • 22,372
  • 32
  • 121
  • 175