public Object getIdentifier(Object entity) {
   final Class entityClass = Hibernate.getClass(entity);
   final ClassMetadata classMetadata = emf.getSessionFactory().getClassMetadata(entityClass);
   if (classMetadata == null) {
     throw new IllegalArgumentException(entityClass + " is not an entity");
   }
   // TODO does that work for @IdClass?
   return classMetadata.getIdentifier(entity);
 }
  public EntityInformation[] locate(EntityManagerFactory entityManagerFactory, JpaGpsDevice device)
      throws JpaGpsDeviceException {

    CompassGpsInterfaceDevice gps = (CompassGpsInterfaceDevice) device.getGps();

    HibernateEntityManagerFactory hibernateEntityManagerFactory =
        (HibernateEntityManagerFactory) entityManagerFactory;
    SessionFactory sessionFactory = hibernateEntityManagerFactory.getSessionFactory();

    ArrayList<EntityInformation> entitiesList = new ArrayList<EntityInformation>();

    Map allClassMetaData = sessionFactory.getAllClassMetadata();
    for (Object o : allClassMetaData.keySet()) {
      String entityname = (String) o;
      if (!gps.hasMappingForEntityForIndex((entityname))) {
        if (log.isDebugEnabled()) {
          log.debug("Entity [" + entityname + "] does not have compass mapping, filtering it out");
        }
        continue;
      }

      ClassMetadata classMetadata = (ClassMetadata) allClassMetaData.get(entityname);
      if (shouldFilter(entityname, classMetadata, allClassMetaData, device)) {
        continue;
      }
      Class<?> clazz = classMetadata.getMappedClass();
      ResourceMapping resourceMapping = gps.getMappingForEntityForIndex(entityname);
      EntityInformation entityInformation =
          new EntityInformation(
              clazz,
              entityname,
              new HibernateJpaQueryProvider(clazz, entityname),
              resourceMapping.getSubIndexHash().getSubIndexes());
      entitiesList.add(entityInformation);
      if (log.isDebugEnabled()) {
        log.debug("Entity [" + entityname + "] will be indexed");
      }
    }
    return entitiesList.toArray(new EntityInformation[entitiesList.size()]);
  }