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

Get a Column Name from Class in Hibernate

this is not a homework or the actual code. It is a quick example created to explain the situation. public student { private long studentId; Private long studentName; @Column(name = "ID") getStudentId(){ } @Column(name =…
Praveen
  • 101
  • 14
0
votes
1 answer

Hibernate left join constraint in a many-to-many relationship

I have built a list of taggable documents, with a many-to-many relationship between the tags and the documents. I would now like to use the hibernate criteria mechanism to query a "summary" of each tag, which includes a count of how often a…
krotscheck
  • 91
  • 1
  • 6
0
votes
0 answers

javax.el.PropertyNotFoundException: Target Unreachable, 'teacher' returned null

i'm newbie and don't good with Eng now i've problem Return null when I insert new row of table here is Error . INFO: javax.el.PropertyNotFoundException: /index.xhtml @143,70 value="#{studentCtrl.student.teacher.teachId}": Target Unreachable,…
Bun Chu
  • 1
  • 1
0
votes
1 answer

Grails row number criteria

Short question: How do I get the row number as an extra column in grails criteria? I could only find rowCount which is not what I need
Bernhard
  • 444
  • 1
  • 4
  • 19
0
votes
0 answers

Hibernate- Getting one record will all null values from database

I am trying to get data using hibernate. My query is correct but record for particular id does not exist it still returns one record (return list size is 1) with all null values. Below is part of code: org.hibernate.SQLQuery query =…
S Singh
  • 1,403
  • 9
  • 31
  • 47
0
votes
1 answer

Hibernate criteria with collections and "not contains"

public class Game{ @Id private int id; @ManyToMany @JoinTable( name="game_community" , joinColumns={ @JoinColumn(name="game_id", nullable=false) } , inverseJoinColumns={ …
0
votes
1 answer

grails criteria :How to select all columns in mysql and at the same time format the date then use like

I'm currently creating a search functionality for my page. The data will be coming from DB. In the HTML, the date is displayed in this format dd/mm/yyyy. What I want to do is, in the select query, I want to select the all columns and the date…
user3714598
  • 1,733
  • 5
  • 28
  • 45
0
votes
0 answers

SQLException in Hibernate: ORDER BY items must appear in the select list if SELECT DISTINCT

I am trying to modify a dao method with a distinct count on a column: I had: Criteria crit = statelessSession.createCriteria(APRecord.class, "apr"); crit.createAlias("mAId", "mId", Criteria.INNER_JOIN); crit.addOrder(…
Jay
  • 471
  • 1
  • 4
  • 11
0
votes
1 answer

Hibernate Criteria - org.hibernate.QueryException: could not resolve property:

I have setter and getter in my model class but still getting Exception. this is my model class. @Entity @Table(name="A_CPView") public class APRecord extends AbstractAPRecord implements ARecord { private AMaID mAiD; …
Jay
  • 471
  • 1
  • 4
  • 11
0
votes
3 answers

Writing sql query in hibernate

I have a sql query: select COUNT (distinct agentG) as count from Test_CPView where kNum = ‘test k1’ and pName = ‘test p1’ I'm trying to write into criteria query but it hasn't worked for me: statelessSession =…
Jay
  • 471
  • 1
  • 4
  • 11
0
votes
1 answer

How can I get one database entry with max value using hibernate criteria

If I have a class called Person as public class Person{ private int id; private int age; } How can I get the person object with max age? when I use criteria.setProjection(Projections.max("age) ), it will return me the max age, and then I should…
Neil
  • 2,714
  • 11
  • 29
  • 45
0
votes
2 answers

Grails - HQL to CriteriaBuilder

I have been struggling with understanding how to use criteria builders. On the very simple scenarios they are straight forward. But how would the following HQL be expressed? def pkg_query = "select p from Package as p join p.orgs as orgRole where…
Giannis
  • 5,286
  • 15
  • 58
  • 113
0
votes
1 answer

Querying property of sub-entity with hibernate criteria

I am trying to build a query with Hibernate Criteria. I have two tables (Table A and Table B) and they are MANY - TO - MANY connected. Table B has a property, id, that I would like to query to filter for Table A. So for example : This is my TableA…
Breiti
  • 579
  • 5
  • 21
0
votes
1 answer

Create subquery in Criteria Query

I need to create subquery using the Criteria API the current Criteria query which i have created is Criteria propCriteria = session.createCriteria(PropertyDetail.class); propCriteria.createAlias("property","prop"); …
R Goyal
  • 1
  • 2
0
votes
2 answers

Compare two tables of the same objects and select the different ones

I have a joint table named EmployeeTask join by Employee and Task. Relationship: Employee (ONE)----(MANY) EmployeeTask (MANY)----(ONE) Task. So now I have an employee, and I use his employee ID to find all the employeeTask this employee has been…
Ray
  • 25
  • 1
  • 8