Child pages
  • Using the EntityManager Service
Skip to end of metadata
Go to start of metadata


This explains basic usage of the Sakai EntityManager Service. This service is used to find out things about Sakai legacy entities and look them up by references or contexts.

Accessing the EntityManager

  • You can use Spring Framework to inject the service or use the cover
  1. Using Spring to get the service for your class (e.g. YourAppClass) (recommended)
    1. Add the EntityManager bean to the bean for YourAppClass
      <bean id="org.sakaiproject.yourapp.logic.YourAppClass"
      	<property name="entityManager"
      		ref="org.sakaiproject.entity.api.EntityManager" />
    2. Add a variable and setter to YourAppClass to use the service in like so:
      private EntityManager entityManager;
      public void setEntityManager(EntityManager entityManager) {
      	this.entityManager = entityManager;
  2. Using the Component Manager to get the service
    • Note: This is not the recommended method, you should be using Spring to inject the service
    1. Use the CM cover to get the service
      import org.sakaiproject.component.cover.ComponentManager;
      import org.sakaiproject.entity.api.EntityManager;
        private EntityManager entityManager;
          entityManager = (EntityManager) ComponentManager.get(EntityManager.class);

Getting the Reference for an Entity

  1. Get the id of any Entity in Sakai
  2. Use the EntityManager service to get the Reference
  3. Check if the type of the reference is known
  4. Use a service (e.g. SiteService) to compare the type
String entityId = entity.getId(); // (1)
Reference r = entityManager.newReference(entityId); // (2)
if(r.isKnownType()) { // (3)
   if(r.getType().equals(SiteService.APPLICATION_ID)) { // (4)
      // do something since this is a site
  • No labels


  1. possible typo in the code block. Should be entityId, not authzGroupId, as in:

    String entityId = (String); // (1)
    Reference r = entityManager.newReference( entityId); // (2)

    1. Good point. Example updated.