Hibernate named query using xml

Named query is a concept of using queries by name. First a query is defined and a name is assigned to it. Then it can be used anywhere by this alias name. Syntax of hibernate named query using xml. <query name="queryName"> <![CDATA[queryString]]> </query><query name="queryName"> <![CDATA[queryString]]> </query> How to call a named query? We can call … Read more

Projections Hibernate

Projections class provides the methods to perform the operation on a particular column. Commonly used methods of Projections class: 1. Projections.rowCount: Return the total no. of rows. Syntax: Projections.rowCount() 2. Projections.avg: Return the average of a specified property. Syntax: Projections.avg(“property”) 3. Projections.countDistinct: Return the distinct count of a property. Syntax: Projections.countDistinct(“property”) 4. Projections.max: Return the maximum … Read more

Pagination in hibernate

Criteria interface provides the methods for performing pagination operations. Methods of Criteria interface used for pagination query: 1. setFirstResult(int firstResult): Set the first row of your result based on the firstResult value. Row index starts from 0. Syntax: public Criteria setFirstResult(int firstResult) 2. setMaxResults(int maxResults): Set the maximum number of records in your result. Syntax: … Read more

Order By Hibernate

Order class provides the methods for performing ordering operations. Methods of Order class: 1. Order.asc: To sort the records in ascending order based on the specified property. Syntax: Order.asc(“property”) 2. Order.desc: To sort the records in descending order based on the specified property. Syntax: Order.desc(“property”) Example: Order By Hibernate Student.java /** * This class represents … Read more

Restrictions query Hibernate

Restrictions class provides the methods to restrict the search result based on the restriction provided. Commonly used Restriction class methods: 1. Restrictions.eq: Make a restriction that the property value must be equal to the specified value. Syntax: Restrictions.eq(“property”, specifiedValue) 2. Restrictions.lt: Make a restriction that the property value must be less than the specified value. … Read more

Basic query hibernate

HCQL stands for Hibernate Criteria Query Language. HCQL is mainly used in search operations and works on filtration rules and logical conditions. Syntax: Criteria cr = session.createCriteria(persistantClassName.class); Example: Student.java /** * This class represents a persistent class for Student. * @author w3spoint */ public class Student { //data members private int studentId; private String firstName; … Read more

Hibernate Criteria Query Language (HCQL)

HCQL: HCQL stands for Hibernate Criteria Query Language. As we discussed HQL provides a way of manipulating data using objects instead of database tables. Hibernate also provides more object oriented alternative ways of HQL. Hibernate Criteria API provides one of these alternatives. HCQL is mainly used in search operations and works on filtration rules and logical … Read more

Hibernate Query Language (HQL)

HQL: HQL stands for Hibernate Query Language. HQL syntax is quite similar to SQL syntax but it performs operations on objects and properties of persistent classes instead of tables and columns. Hibernate framework translate HQL queries into database specific queries to perform action. Query interface provides the methods and functionality to represent and manipulate a … Read more

Hibernate component mapping

Component Class: A class is said to be a component class if it is completely depends upon its container class life cycle and it is stored as a member variable not as an instance. Component mapping: If an entity class has a reference entity as a component variable then this property can mapped by using … Read more

Hibernate Many-to-Many

Many-to-Many relationship in real world: Two items are said to be in Many-to-Many relationship if many occurrence of item are belong to the many occurrences of other item and vice versa. E.g. Many student – Many subject. Many-to-Many relationship in programming: Two entities are said to be in Many-to-Many relationship if many occurrence of entity … Read more