use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class CompositeIdTest method testSecondaryTableWithCompositeId.
@Test
public void testSecondaryTableWithCompositeId() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Channel channel = new Channel();
s.persist(channel);
Presenter pres = new Presenter();
pres.name = "Tim Russet";
s.persist(pres);
TvMagazinPk pk = new TvMagazinPk();
TvProgram program = new TvProgram();
program.time = new Date();
program.id = pk;
program.text = "Award Winning Programming";
pk.channel = channel;
pk.presenter = pres;
s.persist(program);
tx.commit();
s.clear();
tx = s.beginTransaction();
program = (TvProgram) s.createQuery("from TvProgram pr").uniqueResult();
assertNotNull(program.id);
assertNotNull(program.id.channel);
assertEquals(channel.id, program.id.channel.id);
assertNotNull(program.id.presenter);
assertNotNull(program.text);
assertEquals(pres.name, program.id.presenter.name);
s.delete(program);
s.delete(program.id.channel);
s.delete(program.id.presenter);
tx.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class CompositeIdTest method testSecondaryTableWithIdClass.
@Test
public void testSecondaryTableWithIdClass() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Channel channel = new Channel();
s.persist(channel);
Presenter pres = new Presenter();
pres.name = "Bob";
s.persist(pres);
TvProgramIdClass program = new TvProgramIdClass();
program.time = new Date();
program.channel = channel;
program.presenter = pres;
program.text = "Jump the shark programming";
s.persist(program);
tx.commit();
s.clear();
tx = s.beginTransaction();
program = (TvProgramIdClass) s.createQuery("from TvProgramIdClass pr").uniqueResult();
assertNotNull(program.channel);
assertEquals(channel.id, program.channel.id);
assertNotNull(program.presenter);
assertNotNull(program.text);
assertEquals(pres.name, program.presenter.name);
s.delete(program);
s.delete(program.channel);
s.delete(program.presenter);
tx.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class CompositeIdTest method testOneToOneInCompositePk.
@Test
public void testOneToOneInCompositePk() throws Exception {
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
B b = new B();
C c = new C();
s.persist(b);
s.persist(c);
A a = new A();
a.setAId(new AId());
a.getAId().setB(b);
a.getAId().setC(c);
s.persist(a);
s.flush();
s.clear();
a = (A) s.get(A.class, a.getAId());
assertEquals(b.getId(), a.getAId().getB().getId());
tx.rollback();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class EmbeddedTest method testTransientMergeComponentParent.
@Test
@TestForIssue(jiraKey = "HHH-3868")
public void testTransientMergeComponentParent() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Book b = new Book();
b.setIsbn(UUID.randomUUID().toString());
b.setSummary(new Summary());
b = (Book) s.merge(b);
tx.commit();
s.close();
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class EmbeddedTest method testEmbeddableInsideEmbeddable.
// make sure we support collection of embeddable objects inside embeddable objects
@Test
public void testEmbeddableInsideEmbeddable() throws Exception {
Session s;
Transaction tx;
Collection<URLFavorite> urls = new ArrayList<URLFavorite>();
URLFavorite urlFavorite = new URLFavorite();
urlFavorite.setUrl("http://highscalability.com/");
urls.add(urlFavorite);
urlFavorite = new URLFavorite();
urlFavorite.setUrl("http://www.jboss.org/");
urls.add(urlFavorite);
urlFavorite = new URLFavorite();
urlFavorite.setUrl("http://www.hibernate.org/");
urls.add(urlFavorite);
urlFavorite = new URLFavorite();
urlFavorite.setUrl("http://www.jgroups.org/");
urls.add(urlFavorite);
Collection<String> ideas = new ArrayList<String>();
ideas.add("lionheart");
ideas.add("xforms");
ideas.add("dynamic content");
ideas.add("http");
InternetFavorites internetFavorites = new InternetFavorites();
internetFavorites.setLinks(urls);
internetFavorites.setIdeas(ideas);
FavoriteThings favoriteThings = new FavoriteThings();
favoriteThings.setWeb(internetFavorites);
s = openSession();
tx = s.beginTransaction();
s.persist(favoriteThings);
tx.commit();
tx = s.beginTransaction();
s.flush();
favoriteThings = (FavoriteThings) s.get(FavoriteThings.class, favoriteThings.getId());
assertTrue("has web", favoriteThings.getWeb() != null);
assertTrue("has ideas", favoriteThings.getWeb().getIdeas() != null);
assertTrue("has favorite idea 'http'", favoriteThings.getWeb().getIdeas().contains("http"));
assertTrue("has favorite idea 'http'", favoriteThings.getWeb().getIdeas().contains("dynamic content"));
urls = favoriteThings.getWeb().getLinks();
assertTrue("has urls", urls != null);
URLFavorite[] favs = new URLFavorite[4];
urls.toArray(favs);
assertTrue("has http://www.hibernate.org url favorite link", "http://www.hibernate.org/".equals(favs[0].getUrl()) || "http://www.hibernate.org/".equals(favs[1].getUrl()) || "http://www.hibernate.org/".equals(favs[2].getUrl()) || "http://www.hibernate.org/".equals(favs[3].getUrl()));
tx.commit();
s.close();
}
Aggregations