package kuues; import java.util.ArrayList; import java.util.List; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.AnnotationConfiguration; public class Test1 { public static void main(String[] arg) { AnnotationConfiguration c = new AnnotationConfiguration().configure("kuues/hibernate6.cfg.xml"); SessionFactory sf = c.buildSessionFactory(); Session s = sf.openSession(); Transaction tx = s.beginTransaction(); try { Peremees p=new Peremees(); p.setEesnimi("Juku"); Koer k1=new Koer(); k1.setKoeranimi("Muki"); k1.setPeremees(p); Koer k2=new Koer(); k2.setKoeranimi("Muri"); k2.setPeremees(p); List koerad=new ArrayList(); koerad.add(k1); koerad.add(k2); p.setKoerad(koerad); int pid=(int)s.save(p); tx.commit(); System.out.println("Salvestati peremees "+pid); } catch (Exception e) { System.out.println(e.getMessage().toString()); tx.rollback(); } s.close(); } }