/** @see DATAJPA-527 */ @Test public void testExistsWithEmbeddedId() { EmbeddedIdExampleDepartment dep1 = new EmbeddedIdExampleDepartment(); dep1.setDepartmentId(1L); dep1.setName("Dep1"); EmbeddedIdExampleEmployeePK key = new EmbeddedIdExampleEmployeePK(); key.setDepartmentId(1L); key.setEmployeeId(1L); EmbeddedIdExampleEmployee emp = new EmbeddedIdExampleEmployee(); emp.setDepartment(dep1); emp.setEmployeePk(key); emp = employeeRepositoryWithEmbeddedId.save(emp); key.setDepartmentId(emp.getDepartment().getDepartmentId()); key.setEmployeeId(emp.getEmployeePk().getEmployeeId()); assertThat(employeeRepositoryWithEmbeddedId.exists(key), is(true)); }
/** * @see DATAJPA-269 * @see Final JPA 2.0 Specification 2.4.1.3 Derived Identities Example 3 */ @Test public void shouldSupportSavingEntitiesWithCompositeKeyClassesWithEmbeddedIdsAndDerivedIdentities() { EmbeddedIdExampleDepartment dep = new EmbeddedIdExampleDepartment(); dep.setName("TestDepartment"); dep.setDepartmentId(-1L); EmbeddedIdExampleEmployee emp = new EmbeddedIdExampleEmployee(); emp.setDepartment(dep); emp.setEmployeePk(new EmbeddedIdExampleEmployeePK()); emp = employeeRepositoryWithEmbeddedId.save(emp); EmbeddedIdExampleEmployeePK key = new EmbeddedIdExampleEmployeePK(); key.setDepartmentId(emp.getDepartment().getDepartmentId()); key.setEmployeeId(emp.getEmployeePk().getEmployeeId()); EmbeddedIdExampleEmployee persistedEmp = employeeRepositoryWithEmbeddedId.findOne(key); assertThat(persistedEmp, is(notNullValue())); assertThat(persistedEmp.getDepartment(), is(notNullValue())); assertThat(persistedEmp.getDepartment().getName(), is(dep.getName())); }