Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.mesut.secondarytable; import java.util.Calendar; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; /** * * @author mesut */ public class Main { public static void main(String[] args) { Personel personel = new Personel(); personel.setName("Mesut"); personel.setSurname("Yakut"); personel.setAddress("Diyarbakr"); personel.setPhone("1234567"); personel.setHireDate(Calendar.getInstance()); //----------------------------------------------- SessionFactory sf = new Configuration().configure().buildSessionFactory(); Session session = sf.openSession(); session.beginTransaction(); session.save(personel); session.getTransaction().commit(); //--------------------------------------------------- session.beginTransaction(); personel = null; personel = (Personel) session.get(Personel.class, 1); System.out.println("Id: " + personel.getId()); System.out.println("Name: " + personel.getName()); System.out.println("Surname: " + personel.getSurname()); System.out.println("Address: " + personel.getAddress()); System.out.println("Phone: " + personel.getPhone()); System.out.println("Hire Date: " + personel.getHireDate()); session.getTransaction().commit(); session.close(); sf.close(); } }