private void checkEntityId(Object entityId) {
    if (entityId == null) {
      throw new IllegalArgumentException("Invalid null entity id given");
    }

    EntityType<?> entityType =
        em.getMetamodel()
            .entity(
                joinManager
                    .getRootNodeOrFail(
                        "Paginated queries do not support multiple from clause elements!")
                    .getPropertyClass());
    Attribute<?, ?> idAttribute = JpaUtils.getIdAttribute(entityType);
    Class<?> idType = JpaUtils.resolveFieldClass(entityType.getJavaType(), idAttribute);

    if (!idType.isInstance(entityId)) {
      throw new IllegalArgumentException(
          "The type of the given entity id '"
              + entityId.getClass().getName()
              + "' is not an instance of the expected id type '"
              + idType.getName()
              + "' of the entity class '"
              + entityType.getJavaType().getName()
              + "'");
    }
  }
Esempio n. 2
0
 @Test
 public void testGetJoinColumnNamesFromElementCollectionFieldWithoutCollectionTable() {
   HashMap<String, String> joinColumnNames = new HashMap<String, String>();
   joinColumnNames.put("#", "employees_employee_id");
   PropertyDefinition emailAdresses = employeeDefinition.property("emailAddresses");
   SchemaMapper schemaMapper =
       JpaHibernateSchemaMapper.usingNamingStrategyOf(getEntityManagerFactory());
   assertEquals(
       joinColumnNames,
       JpaUtils.getJoinColumnNamesFromJpaAnnotatedField(
           schemaMapper, metamodel.entity(Employee.class), emailAdresses.getField()));
 }
Esempio n. 3
0
  @Test
  public void testGetElementCollectionColumnNames() {
    JpaMetaModelGenerator jpaMetaModelGenerator =
        new JpaMetaModelGenerator(getEntityManagerFactory());
    MetaModel metaModel = jpaMetaModelGenerator.generate();

    Set<String> columnNames = new HashSet<String>();
    columnNames.add("phone_model");
    columnNames.add("phone_number");

    assertEquals(
        columnNames,
        JpaUtils.getElementCollectionColumnNames(employeeDefinition.property("phones"), metaModel));
  }
Esempio n. 4
0
 @Test
 public void testCreateEntityManager() {
   EntityManager em = JpaUtils.createEntityManager(getEntityManagerFactory());
   assertNotNull(em);
   assertNotNull(em.getProperties());
 }