/** @see DATAJPA-527 */ @Test public void testExistsWithIdClass() { IdClassExampleDepartment dep = new IdClassExampleDepartment(); dep.setName("TestDepartment"); dep.setDepartmentId(-1); IdClassExampleEmployee emp = new IdClassExampleEmployee(); emp.setDepartment(dep); employeeRepositoryWithIdClass.save(emp); IdClassExampleEmployeePK key = new IdClassExampleEmployeePK(); key.setDepartment(dep.getDepartmentId()); key.setEmpId(emp.getEmpId()); assertThat(employeeRepositoryWithIdClass.exists(key), is(true)); }
/** * @see DATAJPA-269 * @see Final JPA 2.0 Specification 2.4.1.3 Derived Identities Example 2 */ @Test public void shouldSupportSavingEntitiesWithCompositeKeyClassesWithIdClassAndDerivedIdentities() { IdClassExampleDepartment dep = new IdClassExampleDepartment(); dep.setName("TestDepartment"); dep.setDepartmentId(-1); IdClassExampleEmployee emp = new IdClassExampleEmployee(); emp.setDepartment(dep); employeeRepositoryWithIdClass.save(emp); IdClassExampleEmployeePK key = new IdClassExampleEmployeePK(); key.setDepartment(dep.getDepartmentId()); key.setEmpId(emp.getEmpId()); IdClassExampleEmployee persistedEmp = employeeRepositoryWithIdClass.findOne(key); assertThat(persistedEmp, is(notNullValue())); assertThat(persistedEmp.getDepartment(), is(notNullValue())); assertThat(persistedEmp.getDepartment().getName(), is(dep.getName())); }
/** @see DATAJPA-497 */ @Test public void sortByEmbeddedPkFieldInCompositePkWithIdClassInQueryDsl() { IdClassExampleDepartment dep1 = new IdClassExampleDepartment(); dep1.setDepartmentId(1L); dep1.setName("Dep1"); IdClassExampleDepartment dep2 = new IdClassExampleDepartment(); dep2.setDepartmentId(2L); dep2.setName("Dep2"); IdClassExampleEmployee emp1 = new IdClassExampleEmployee(); emp1.setEmpId(3L); emp1.setDepartment(dep2); emp1 = employeeRepositoryWithIdClass.save(emp1); IdClassExampleEmployee emp2 = new IdClassExampleEmployee(); emp2.setEmpId(2L); emp2.setDepartment(dep1); emp2 = employeeRepositoryWithIdClass.save(emp2); IdClassExampleEmployee emp3 = new IdClassExampleEmployee(); emp3.setEmpId(1L); emp3.setDepartment(dep2); emp3 = employeeRepositoryWithIdClass.save(emp3); QIdClassExampleEmployee emp = QIdClassExampleEmployee.idClassExampleEmployee; List<IdClassExampleEmployee> result = employeeRepositoryWithIdClass.findAll( emp.department.departmentId.eq(dep2.getDepartmentId()), emp.empId.asc()); assertThat(result, is(notNullValue())); assertThat(result, hasSize(2)); assertThat(result.get(0), is(emp3)); assertThat(result.get(1), is(emp1)); }