コード例 #1
0
  /** @see DATAJPA-472 */
  @Test
  public void shouldSupportFindAllWithPageableAndEntityWithIdClass() throws Exception {

    if (Package.getPackage("org.hibernate.cfg").getImplementationVersion().startsWith("4.1.")) {

      // we expect this test to fail on 4.1.x - due to a bug in hibernate - remove as soon as 4.1.x
      // fixes the issue.
      expectedException.expect(InvalidDataAccessApiUsageException.class);
      expectedException.expectMessage("No supertype found");
    }

    IdClassExampleDepartment dep = new IdClassExampleDepartment();
    dep.setName("TestDepartment");
    dep.setDepartmentId(-1);

    IdClassExampleEmployee emp = new IdClassExampleEmployee();
    emp.setDepartment(dep);
    emp = employeeRepositoryWithIdClass.save(emp);

    Page<IdClassExampleEmployee> page =
        employeeRepositoryWithIdClass.findAll(new PageRequest(0, 10));

    assertThat(page, is(notNullValue()));
    assertThat(page.getTotalElements(), is(1L));
  }
コード例 #2
0
  /** @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));
  }
コード例 #3
0
  /** @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));
  }
コード例 #4
0
  /**
   * @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()));
  }