Posts

Showing posts from 2015

Hibernate-Inheritance Mapping with XML

Image
hibernate.cfg.xml <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory>     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Test</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">minu</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="hbm2ddl.auto">update</property> <mapping resourc

Hibernate -Collection Mapping with annotations

Image
hibernate.cfg.xml <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory>     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Test</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">minu</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="hbm2ddl.auto">update</property> <mapping class=&

Hibernate Collection Mapping example

Image
hibernate.cfg.xml <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory>     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/Test</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">minu</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <property name="hbm2ddl.auto">update</property> <mapping resourc

Java Hibernate - Part 3- Annotations Example

Image
Program to add Customer details in to MySQL Database using Hibernate 3.2 . Requirements:  Eclipse Keplor, MySQL 5.5,mysql-connector-odbc-5.2.5, Hibernate 3.2 (jars and xml files). Steps create a new java project named Sample1 add all hibernate jars to project build path. copy hibernate.cfg.xml to src folder Open MySQL command prompt  create Test database and use it. create Table named customer. create table customer(cid int primary key auto_increment,cname varchar(20),email varchar(20),phone varchar(15),city varchar(15),bal double); create a package named com.sam.hibernatefiles and write the following Customer.java(Hibernate Persistence class) HibernateUtil.java write the following client side code under package com.sam.hibernatefiles. Lab1A Customer.java package com.sam.hibernatefiles; import javax.persistence.*; @Entity @Table(name="customer") public class Customer { @Id @GeneratedValue(strategy=GenerationType.AUTO)