public JCRRegistrationPersistenceManager(ExoContainer container) throws Exception {
    persister = new JCRPersister(container, JCRPersister.WSRP_WORKSPACE_NAME);

    List<Class> mappingClasses = new ArrayList<Class>(6);
    Collections.addAll(
        mappingClasses,
        ConsumersAndGroupsMapping.class,
        ConsumerMapping.class,
        ConsumerGroupMapping.class,
        RegistrationMapping.class,
        ConsumerCapabilitiesMapping.class,
        RegistrationPropertiesMapping.class);

    persister.initializeBuilderFor(mappingClasses);

    //      persister = NewJCRPersister.getInstance(container);

    ChromatticSession session = persister.getSession();
    mappings =
        session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
    if (mappings == null) {
      mappings =
          session.insert(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
    }
    persister.save(); // needed right now as the session must still be open to iterate over nodes

    for (ConsumerGroupMapping cgm : mappings.getConsumerGroups()) {
      internalAddConsumerGroup(cgm.toConsumerGroup(this));
    }

    for (ConsumerMapping cm : mappings.getConsumers()) {
      ConsumerSPI consumer = cm.toConsumer(this);
      internalAddConsumer(consumer);

      // get the registrations and add them to local map.
      for (Registration registration : consumer.getRegistrations()) {
        internalAddRegistration((RegistrationSPI) registration);
      }
    }

    persister.closeSession(false);
  }
  @Override
  protected ConsumerGroupSPI internalCreateConsumerGroup(String name) throws RegistrationException {
    ConsumerGroupSPI group = super.internalCreateConsumerGroup(name);

    ChromatticSession session = persister.getSession();
    mappings =
        session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
    try {
      ConsumerGroupMapping cgm = mappings.createConsumerGroup(name);
      mappings.getConsumerGroups().add(cgm);
      group.setPersistentKey(cgm.getPersistentKey());
      cgm.initFrom(group);
      persister.closeSession(true);
    } catch (Exception e) {
      persister.closeSession(false);
      throw new RegistrationException(e);
    }

    return group;
  }
  @Override
  protected ConsumerSPI internalCreateConsumer(String consumerId, String consumerName)
      throws RegistrationException {
    ConsumerSPI consumer = super.internalCreateConsumer(consumerId, consumerName);

    ChromatticSession session = persister.getSession();
    mappings =
        session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
    try {
      ConsumerMapping cm = mappings.createConsumer(consumerId);
      mappings.getConsumers().add(cm);
      cm.initFrom(consumer);
      consumer.setPersistentKey(cm.getPersistentKey());
      persister.closeSession(true);
    } catch (Exception e) {
      persister.closeSession(false);
      throw new RegistrationException(e);
    }

    return consumer;
  }