use of org.hibernate.mapping.Join in project hibernate-orm by hibernate.
the class JoinTest method testDefaultValue.
@Test
public void testDefaultValue() throws Exception {
Join join = (Join) metadata().getEntityBinding(Life.class.getName()).getJoinClosureIterator().next();
assertEquals("ExtendedLife", join.getTable().getName());
org.hibernate.mapping.Column owner = new org.hibernate.mapping.Column();
owner.setName("LIFE_ID");
assertTrue(join.getTable().getPrimaryKey().containsColumn(owner));
Session s = openSession();
Transaction tx = s.beginTransaction();
Life life = new Life();
life.duration = 15;
life.fullDescription = "Long long description";
s.persist(life);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Query q = s.createQuery("from " + Life.class.getName());
life = (Life) q.uniqueResult();
assertEquals("Long long description", life.fullDescription);
tx.commit();
s.close();
}
use of org.hibernate.mapping.Join in project hibernate-orm by hibernate.
the class JoinTest method testCompositePK.
@Test
public void testCompositePK() throws Exception {
Join join = (Join) metadata().getEntityBinding(Dog.class.getName()).getJoinClosureIterator().next();
assertEquals("DogThoroughbred", join.getTable().getName());
org.hibernate.mapping.Column owner = new org.hibernate.mapping.Column();
owner.setName("OWNER_NAME");
assertTrue(join.getTable().getPrimaryKey().containsColumn(owner));
Session s = openSession();
Transaction tx = s.beginTransaction();
Dog dog = new Dog();
DogPk id = new DogPk();
id.name = "Thalie";
id.ownerName = "Martine";
dog.id = id;
dog.weight = 30;
dog.thoroughbredName = "Colley";
s.persist(dog);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Query q = s.createQuery("from Dog");
dog = (Dog) q.uniqueResult();
assertEquals("Colley", dog.thoroughbredName);
tx.commit();
s.close();
}
Aggregations