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.elementcollection; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; /** * * @author mesut */ public class Main { public static void main(String[] args) { Uye uye1 = new Uye(); uye1.setAdi("Mehmet"); uye1.setSoyadi("Kahraman"); Adres adres1 = new Adres(); adres1.setSehir("Diyarbakr"); adres1.setIlce("Kayapnar"); adres1.setMahalle("Diclekent"); adres1.setCadde("Mahabad Bulvar"); Adres adres2 = new Adres(); adres2.setSehir("Ankara"); adres2.setIlce("ankaya"); adres2.setMahalle("Bahelievler"); adres2.setCadde("7. Cadde"); uye1.getAdresListesi().add(adres1); uye1.getAdresListesi().add(adres2); //----------------------------------------------- Uye uye2 = new Uye(); uye2.setAdi("Mert"); uye2.setSoyadi("Kalkan"); Adres adres3 = new Adres(); adres3.setSehir("ehir3"); adres3.setIlce("le 3"); adres3.setMahalle("Mahalle 3"); adres3.setCadde("Cadde 3"); Adres adres4 = new Adres(); adres4.setSehir("ehir 4"); adres4.setIlce("le 4"); adres4.setMahalle("Mahalle 4"); adres4.setCadde("Cadde 4"); uye2.getAdresListesi().add(adres3); uye2.getAdresListesi().add(adres4); //-------------------------------------------------- SessionFactory sf = new Configuration().configure().buildSessionFactory(); Session session = sf.openSession(); session.beginTransaction(); session.save(uye1); session.save(uye2); session.getTransaction().commit(); session.close(); sf.close(); } }