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
1 answer

hibernate query by example caching

I have the following Mapped entity: @Table(uniqueConstraints = @UniqueConstraint(columnNames = { "eKey-field-1", "eKey-field-2", "eKey-field-3" })) class EntityMapped { @Id @GeneratedValue... Long Id; @Embedded EntityKeyMapped…
Bogdan
  • 702
  • 3
  • 6
  • 22
0
votes
2 answers

Use Criteria to select a particular field from DB?

I have a method like below public List getSimilarResourceNames(String resourceName){ String searchString = "%"+resourceName+"%"; Session session = getSession(); Criteria criteria = session.createCriteria(Resource.class); …
robin
  • 1,893
  • 1
  • 18
  • 38
0
votes
1 answer

row multiplication in Hibernate Criteria

How to implement the following SQL query using Hibernate Criteria API: SELECT SUM(field1) as s, SUM(field1 * field2) as m FROM table
Kaiser
  • 748
  • 7
  • 21
0
votes
2 answers

Count rows on distinct select with multiple columns

I have been searching for some time but not found enough answers to do this myself. I have an MsSQL that looks like this: select count(*) from ( select distinct supplierName, supplierNr from dbo.InvoiceTypeBean ) as a This returns what I…
Jens Henrik
  • 99
  • 1
  • 8
0
votes
1 answer

Migration from toplink/eclipselink equalOuterJoin to Hibernate Criteria

I am migrating really old application from toplink to the Hibernate. An i have the folowing code: ExpressionBuilder expHVLMAVI ... expHVLMAVI.anyOfAllowingNone(perf2CollectionString).get("bereichsCode") .equalOuterJoin(bereichsCode) Any ideas how…
serg
  • 1,003
  • 3
  • 16
  • 26
0
votes
1 answer

Hibernate criteria API with "in clause"

I have native SQL, that I want to move to the Hibenate's criteria API, Here it is: SELECT * FROM HV_LMA_VI t0 WHERE t0.HV_ID IN (SELECT t2.HV_ID FROM Z_LSZERG_HV t4, Z_LSZ_ERG t3, …
serg
  • 1,003
  • 3
  • 16
  • 26
0
votes
1 answer

how to create a hibernate projection that searches one column for any value = true

I have a hibernate entity Type like so @Entity @Table(name = "type") public class Type { @Column(name = "enabled") private boolean enabled = false; } and I want to create a function that returns if any row in the Type table has enabled = true. …
Mark
  • 3,137
  • 4
  • 39
  • 76
0
votes
1 answer

Hibernate criteria and comparator

I'm using hibernate template and it's findByCriteria(criteria, offset, maxResults) method to get results paginated. To get results ordered before calling findByCriteria I set in criteria OrderBy property. The problem is a want to order this…
stacy
  • 11
  • 1
  • 10
0
votes
1 answer

In Hibernate Query Language is there any way to select from the result of Inner Query?

I want to select Count of the result Of Sub Query e.g. SELECT COUNT(*) from (SELECT * FROM ENTITY Group By ); Is there any way to do this in HQL?
Animesh Agrawal
  • 161
  • 2
  • 16
0
votes
2 answers

Select all entities of exact class, but not derived from it using NHibernate Criteria API

I have two classes: Cat and DomesticCat, that extends Cat. I want to select all Cats, but no oneDomesticCat. How to do it using NHibernate criteria API?
Serge S.
  • 4,855
  • 3
  • 42
  • 46
0
votes
0 answers

Hibernate Joining on Composite Primary Key

Need a help on hibernate join. Problem - I have three hibernate pojo classes. 1. ReportRequest 2. AnalysisType 3. Application I created the tables from the hibernate and all of them are created successfully. So it seems that there are no issue in…
0
votes
2 answers

Grails hasMany and criteria not working as expected

I have two models with a hasMany relation class Puturru implements Serializable { String name Set fuas static hasMany = [fuas: Fua] static constraints = { fuas(nullable: true) } } And class Fua { String…
esauro
  • 1,276
  • 10
  • 17
0
votes
0 answers

Using Hibernate getCurrentSession().delete method delete the list of objects

I want to delete the list of Object with the getCurrentSession().delete() method. I found the optional way by writing the query like getCurrentSession().createQuery("delete from Student where studentId =1").executeUpdate(); And I have come to…
UtkarshBhavsar
  • 249
  • 3
  • 23
0
votes
1 answer

Criteria API: can I use Criteria with unidirectional ManyToMany association?

I have User entity: @Entity @Table(name = "users") public class User implements Serializable{ @Id @GeneratedValue private Long id; @Column(nullable = false) private String name; And Project entity, which has unidirectional…
0
votes
2 answers

Hibernate Criteria: counting the most recent entries, grouped per attribute

This is a knot I find quite hard to untie. My requirement is to use the Criteria API. I have a Team class defined as follows: @Entity @Table(name="TEAMS") public class Team{ private Set states = new HashSet(); …
MaVVamaldo
  • 2,505
  • 7
  • 28
  • 50