HIBERNATE - Getting Started With Hibernate

Hibernate Sample Code (Inserting new record)

Here is how you can use Hibernate in your programs. Typical Hibernate programs begin with configuration that is required for Hibernate. Hibernate can be configured in two ways. Programmatically and Configuration file based. In Configuration file based mode, hibernate looks for configuration file “hibernate.cfg.xml” in the claspath. Based on the resource mapping provided hibernate creates mapping of tables and domain objects. In the programmatic configuration method, the details such as JDBC connection details and resource mapping details etc are supplied in the program using Configuration API.

Following example shows programmatic configuration of hibernate.

Configuration config = new Configuration()

Configuration config = new Configuration()
.setProperty("hibernate.dialect", "org.hibernate.dialect. MySQLMyISAMDialect")
.setProperty("hibernate.connection.driver_class", " org.gjt.mm.mysql.Driver")
. . . SessionFactory sessions = config.buildSessionFactory();

In configuration file based approach, “hibernate.cfg.xml” is placed in the classpath, Following Hibernate code can be used in this method.

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
AppLabsUser user = new AppLabsUser();
Transaction tx = session.beginTransaction();
user.setUserCreationDate(new Date());

Hibernate tutorial
Introduction to Hibernate
Overview of Hibernate
Features of Hibernate
Getting Started with Hibernate
Prepare Database
Create Persistent Java Objects
Mapping POJO With Persistence Layer Using Hibernate Mapping Document
Hibernate Configuration File
Hibernate Sample Code (Inserting new record)
Hibernate Sample Code (Quering the database)
Hibernate O/R Mapping
Hibernate Mapping In Depth
Hibernate Query language
Hibernate Complete Example

Use of this website constitutes acceptance of the AllAppLabs.com Terms and Conditions