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

Querying an entity's HashMap

I'm having problems on querying some entity that matches some criteria (key/value - coming from the web) with it's HashMap. The entity looks like this: @Entity class Entity { @ElementCollection @MapKeyColumn(name = "context_key") …
user2054927
  • 969
  • 1
  • 12
  • 30
0
votes
1 answer

Hibernate criteria , rowcount() is only working for firstResult = 0

I am working on pagination and trying to fetch rowcount for every Rest api call sending firstResult and MaxResults with url, for naming conventions I have mentioned firstResult as pageNumber and MaxResults as pageSize and the required piece of code…
Soumyaansh
  • 8,626
  • 7
  • 45
  • 45
0
votes
0 answers

hibernate criteria is not executed

i have one issue in my code @Override public Turno getTurnoRechazado(Turno t) { LOGGER.info("start here"); Session session = this.sessionManager.getSession(); Criteria criteria = session.createCriteria(Turno.class); …
0
votes
1 answer

HIbernate - dont load Lazy Entities in an Eager Association

If I have the following classes in my project @Entity @Table(name = "application_home_screen") public class ApplicationHomeScreenVO implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name =…
Damien Gallagher
  • 981
  • 4
  • 13
  • 25
0
votes
1 answer

Grails : how to best construct a hibernate criteria builder to search 'hasMany' relationships with domain instance

I am working on a grails project and would like to leverage hibernate criteria builders to search for instances of a domain object. I would like to find instances where one of the 'hasMany' relationships contains domain object with certain ids. …
Mike Croteau
  • 1,062
  • 2
  • 16
  • 43
0
votes
1 answer

Criteria query, group by

I have a simple criteria query: prc.arrDomainACST = c .createAlias('ACCR_DOMA_KY', 'd', c.LEFT_JOIN) .withProjections(property = 'ACMA_KY,d.SHORT_DESCRIPTION_LB,ACCR_DOMA_KY.DOMA_KY') …
Junglefish
  • 273
  • 1
  • 4
  • 16
0
votes
1 answer

Hibernate criteria order by a linking table column

I have membership and person tables that are linked with manyToMany relationship via a person_membership table. The person_membership table include person_id, membership_id and a sequence_number. The Membership entity has the below code to link to…
zoro74
  • 171
  • 15
0
votes
0 answers

Hibernate 'AND' and 'OR' using Criteria for preexisting criteria

I have an existing criteria to which I want to add one more criterion that ORs with the preexisting criteria. I'd like to add that I cannot control how the preexisting criteria is constructed. For eg: My preexisting criteria translates to the…
woggle
  • 11
  • 2
0
votes
1 answer

Hibernate row count on Criteria with already set Projection

For a grid component I have in my web applications I have a "GridModel" class which gets passed a Criteria. The GridModel class has a method to get the results for a specific page by adding setFirstResult(...) and setMaxResults(...) to the…
Nathan Q
  • 1,892
  • 17
  • 40
0
votes
1 answer

Hibernate Criteria is returning same value for different Restrictions in two consecutive calls

Surprisingly I am getting same value for different Restrictions in two consecutive Criteria calls. I am using Hibernate 4.2.20 final. Please refer my maven dependency. org.hibernate
Suvonkar
  • 2,440
  • 12
  • 34
  • 44
0
votes
1 answer

using inner join criteria language

Have two tables : Rating and Books. Rating table has foreign key to the Books table. These tables are mapped this way : Books : HasMany(x => x.RatingList).Cascade.All().Inverse(); and the Rating table : References(x =>…
LoverBugs
  • 127
  • 1
  • 2
  • 14
0
votes
0 answers

Criteria query with interim table joining

I have Card and Menu with @ManyToMany relation. So, in my DB I have 3 tables(card, menu, card_menu). Also I have wrote sql-query, which takes right data: select * from card as c inner join menu as children on (children.parent_menu=3) inner join…
Ivan Timoshin
  • 601
  • 9
  • 23
0
votes
1 answer

Hibernate CriteriaBuiler .or()

I have constructed the following or predicate for my query. I want to retrieve all orders that either have no customer associated with it, and those that do and have one of several specific statuses. Predicate p1 =…
appel
  • 517
  • 2
  • 7
  • 19
0
votes
0 answers

convert sql query to critera query

Can some one help me convert this to criteria query . I am using Hibernate and when i used this in native query, it returned me an empty result set :( select * from Experiment e,launchman l,launchman_has_servergroups ls,servergroup s where…
Bhavana k
  • 1
  • 1
  • 4
0
votes
1 answer

Criteria on a set of strings

I'm using Hibernate 3.6, and I have a class Shop with a field alternateCodes of type Set, that is mapped as follows:
Maurice Perry
  • 32,610
  • 9
  • 70
  • 97