Entity registry


The framework has to know all entities that describe the application’s domain in order to generate the HBase backend storage operations for it as well as the REST API to manipulate them.

This is the role of the app’s entity registry.

To setup your app’s entity registry, define an object that extends class HEntityRegistry and then register all of your app’s entities with it.


In previous versions of HFactory, the entity registry class was called EntityRegistry. This class is now deprecated and slated for removal in the near future. Please use HEntityRegistry instead.


The entity registry’s API is the following:

abstract class HEntityRegistry {
  /** Registers the specified class as an entity.
    * The HEntity* instances are automatically generated if they
    * don't exist.
  protected def registerEntity[T <: Product: ClassTag: TypeTag](implicit e: HEntity[T]): Unit

  /** Returns the entity instance for the specified class.
    * Raises [[com.ubeeko.hfactory.entities.EntityNotFoundException]] if not found.
  def getEntity[T](implicit ct: ClassTag[T]): HEntity[T]

  /** Returns the entity instance for the specified class or None if not found. */
  def getEntityOpt[T](implicit ct: ClassTag[T]): Option[HEntity[T]]

  /** Returns all registered entity instances. */
  def entities: Seq[HEntity[_]]


The best way to setup an entity registry is to define it and register all entities at the same time. An entity must be registered exactly once. Say an app has entities A, B, and so on. Then its entity registry should be setup as follows:

class X extends HEntityRegistry {

It is an error to register an entity more than once.

The entity registry is available within the app’s body as entityRegistry.

Expanding on the User Directory example, its registry is as follows:

class UserDirectoryRegistry extends HEntityRegistry {

Note that the class name does not matter; however it is good practice to name an app A’s registry as ARegistry.


An app’s entity for case class T can be looked up using entity registry methods getEntity[T] or getEntityOpt[T].

To get the entity of case class User, one would write:

val userEntity = entityRegistry.getEntity[User]

Please refer to the Entities section for a description of the entity API.