Archive | Hibernate RSS feed for this section

Configure MySql database with Hibernate mappings

July 29, 2008

3 Comments

Configure MySql database Configuring MySql database with hibernate is the same as with other databasses.The only difference will be connection url and the database dialect to be specified in the configuration file. This tips provides a basic example configuration file for configuaring the MySql with hibernate. But it doesn’t explain you installing the MySql database. [...]

email

Collection Mapping in Hibernate : one-to-many

July 26, 2008

0 Comments

one-to-many class mapping This article explains how to map two classes in collection mapping. In this example one Author object has the list of Book objects. Both the classes are mapped and will be inserted together into the database. Here this example uses Bag as the collection type. Other collection types available are Set,List,Array. Look [...]

Comparison operators in Hibernate

July 26, 2008

0 Comments

Comparison operators HQL supports all the operators used in the SQL language. But, Criteria API doesn’t support the arithmetic expressions. Apart from that, it is easy to use other operators in the Criteria API itself. This tips provides few basic example programs on using the operators. JavaBeatHibernateExample.java 1 2 3 4 5 6 7 8 [...]

NULL and NOT NULL comparison in the Hibernate API

July 26, 2008

0 Comments

null and not null check While checking for the null and not null values in the Hibernate API, we have to be careful and there is chance for misunderstanding. This tips explains how to compare the null values in the Hibernate query. In Java language, if object==null will return the proper value if it is [...]

How to use named parameters and named query in Hibernate?

July 26, 2008

0 Comments

Named Parameters in Hibernate Query There is two types of query parameters binding in the Hibernate Query. One is positioned parameter and another one is named parameter. But, hibernate recommend to use the named parameters since it is more flexible and powerful compare to the positioned parameter. Here we will look into the named parameter [...]

Pagination in Hibernate Query API

July 26, 2008

1 Comment

Pagination in Hibernate Query API Pagination is the very common problem for the most of the eneterprise applications.When we are retrieving thousands of records from the database, it is not good idea to retrieve all the records at the same time. So, we have to implement some sort of pagination concept in your application to [...]

Three ways to create query in Hibernate

July 26, 2008

12 Comments

Create Query in Hibernate To create query in the Hibernate ORM framework, there is three different types. The folloing are the three ways to create query instance: 1)session.createQuery() 2)session.createSQLQuery() 3)session.createCriteria() We will look into the details of each category in detail. session.createQuery() The method createQuery() creates Query object using the HQL syntax. Fro example session.createSQLQuery() [...]

How to use datasource in Hibernate application?

July 23, 2008

3 Comments

This article explains how to configure datasource in the JBoss application server and how to use the same datasource in the hibernate configuration file.Before looking into the hibernate configuration, we will start with creating datasource inside JBoss application server. Create MySql datasource in JBoss To create datasource for the MySql database inside the JBoss application [...]

Hibernate Criteria Query Example

July 23, 2008

4 Comments

Hibernate Criteria Example Criteria APIs in the hibernate framework is useful for creating the dynamic query to execute.It is an alternative way to write the queries without using HQL. The queries are generated at runtime and excuted on the fly. Application developer need not worry about writing the query in hand, he/she just need to [...]

How to Configure hibernate using XML files?

July 19, 2008

0 Comments

Hibernate Configuration Using XML files for configuring hibernate application is the most widely used approach. This is simple one and less whanges needed in the future. There is two types of configuration we can do using XML files. one is non-managed environment and another one is for managed environment. Here we will explain about the [...]