public void testOneToOneExplicitJoinColumn() throws Exception { assertTrue(SchemaUtil.isColumnPresent("MedicalHistory", "FK1", getCfg())); assertTrue(SchemaUtil.isColumnPresent("MedicalHistory", "FK2", getCfg())); assertTrue(!SchemaUtil.isColumnPresent("MedicalHistory", "firstname", getCfg())); Person e = new Person(); e.id = new PersonId(); e.id.firstName = "Emmanuel"; e.id.lastName = "Bernard"; Session s = openSession(); s.getTransaction().begin(); s.persist(e); MedicalHistory d = new MedicalHistory(); d.patient = e; s.persist(d); s.flush(); s.clear(); PersonId pId = new PersonId(); pId.firstName = e.id.firstName; pId.lastName = e.id.lastName; d = (MedicalHistory) s.get(MedicalHistory.class, pId); assertEquals(pId.firstName, d.patient.id.firstName); s.delete(d); s.delete(d.patient); s.getTransaction().commit(); s.close(); }
public void testOneToOneExplicitJoinColumn() throws Exception { assertTrue(SchemaUtil.isColumnPresent("MedicalHistory", "FK1", getCfg())); assertTrue(SchemaUtil.isColumnPresent("MedicalHistory", "FK2", getCfg())); assertTrue(!SchemaUtil.isColumnPresent("MedicalHistory", "firstname", getCfg())); Person e = new Person(); e.id = new PersonId(); e.id.firstName = "Emmanuel"; e.id.lastName = "Bernard"; Session s = openSession(); s.getTransaction().begin(); s.persist(e); MedicalHistory d = new MedicalHistory(); // d.id = new PersonId(); // d.id.firstName = "Emmanuel"; //FIXME not needed when foreign is enabled // d.id.lastName = "Bernard"; //FIXME not needed when foreign is enabled d.patient = e; s.persist(d); s.flush(); s.clear(); d = (MedicalHistory) s.get(MedicalHistory.class, d.id); assertEquals(d.id.firstName, d.patient.id.firstName); s.getTransaction().rollback(); s.close(); }