Ejemplo n.º 1
0
 @Override
 public Map<String, Map<String, Class<?>>> getTableColumnMap() {
   Metamodel metamodel = entityManager.getEntityManagerFactory().getMetamodel();
   Set<EntityType<?>> entityTypes = metamodel.getEntities();
   Map<String, Map<String, Class<?>>> tableColumnMap =
       new HashMap<String, Map<String, Class<?>>>();
   for (EntityType<?> type : entityTypes) {
     EntityType<Entity> entityType = (EntityType<Entity>) type;
     Set<SingularAttribute<? super Entity, ?>> singularAttributes =
         entityType.getSingularAttributes();
     Map<String, Class<?>> columnMap = new HashMap<String, Class<?>>();
     for (SingularAttribute<? super Entity, ?> singularAttribute : singularAttributes) {
       columnMap.put(singularAttribute.getName(), singularAttribute.getJavaType());
     }
     tableColumnMap.put(entityType.getName(), columnMap);
   }
   return tableColumnMap;
 }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  private static String getEntityIdField(EntityManager em, Class entity) {

    String idProperty = "";

    Metamodel metamodel = em.getMetamodel();
    EntityType e = metamodel.entity(entity);
    Set<SingularAttribute> singularAttributes = e.getSingularAttributes();

    for (SingularAttribute singularAttribute : singularAttributes) {

      if (singularAttribute.isId()) {

        idProperty = singularAttribute.getName();
        break;
      }
    }

    return idProperty;
  }