Posts

Showing posts with the label Hibernate

Types of hibernate bean states

As of we know hibernate follows the ORM features, Java bean class maps with database table. While mapping java bean class with database table it traverse through different types of states. That are Transient, Persistent and Detached states.   Different states of POJO class object: 1. Transient state: Object is created by programmer with data. But is doesn't represent any table row. This object does not contains any primary key value. The object which is created for POJO class and which is not under control of hibernate application resides in transient state. 2. Persistent state: The object that represents table row with primary key and managed under control of hibernate software is called as persistent state. This object will be in synchronization with table row.  H ibernate application developer's uses this kind of object in persistent logic development. 3. Detached state: when session is closed persistent context will be destroyed and all the obje

Hibernate auto increment with example

In previous example we learn how to map java object with database table for manually(not using auto increment) assigned all the values.  To create primary key auto increment application by using hibernate mapping(hbm.xml) or using annotations continue reading this article.  W e need to create a database and create an employee table by using the below query. Table: CREATE table EMPLOYEE( eid integer ( 10 ) primary key not null , firstname varchar ( 30 ), lastname varchar ( 30 ), designation varchar ( 30 ), salary double( 10 , 2 )); Here, we will create a bean/POJO (Plain Old Java Object) class of employee. Employee.java: package com . javatbrains . hibernate ; import java.io.Serializable ; /*This is the POJO class. It contains only Getter and Setter methods*/ public class Employee implements Serializable { private static final long serialVersionUID = - 75885815725314443L ; private int eid ; private String firstName ;

hibernate sample application with example

Hibernate is ORM(Object Relational Mapping) framework for mapping java object with database table. A brief description about Configuration, SessionFactory, Session, Query, Criteria, Transaction and follow the same for sample application creation using hibernate. Configuration:   Configuration is that the initial object you wish to make any of hibernate application and typically making one time throughout the applying initialization. It represents the configuration or properties file providing by hibernate. SessionFactory:   Configuration object is employed to make SessionFactory instance that intern configures hibernate for the applying. SessionFactory object is significant weight part, it's created throughout application start up time and unbroken for later use. The way to do this we are going to see in below application. We would like one SessionFactory object per info employing a separate configuration. Therefore if you victimization multiple databases then you'd ou