session = sessionFactory.openSession();
tx = session.getTransaction();
try {
tx.begin();
for (int i = 156; i < 160; i++) {
final Bar bar = new Bar();
bar.setName("Bar_" + i);
final Foo foo = new Foo("Foo_" + (i + 120));
foo.setBar(bar);
session.save(foo);
final Foo foo2 = new Foo(null);
if (i % 2 == 0)
foo2.setName("LuckyFoo" + (i + 120));
foo2.setBar(bar);
session.save(foo2);
bar.getFooSet().add(foo);
bar.getFooSet().add(foo2);
session.merge(bar);
}
tx.commit();
session.flush();
} catch (final HibernateException he) {