@Override
  public void beforeInvocation() {
    //
    // Prevent the regular JPA Plugin from starting a transaction.
    //
    JPA.entityManagerFactory = null;

    //
    //	If we have no databases defined, and we have a directive to permit this state, allow it.
    //
    if (factoryMap.isEmpty()
        && Play.configuration.getProperty("mjpa.runWithNoDB", "").equals("true")) {
      log.debug("Empty factory map--using dummy factory");
      JPA.entityManagerFactory = getDummyFactory();
      return;
    }

    log.debug("Extracting DB key from request: " + Request.current());

    //
    // Find the database key, so that we'll have one for the transaction.
    //
    String dbKey = keyExtractor.extractKey(Request.current());
    log.debug("Found key: " + dbKey);
    try {
      if (dbKey != null) {
        //
        // Start the transaction
        //
        startTx(dbKey, false);
      }
    } catch (InvalidDatabaseException e) {
      throw new NotFound(e.getMessage());
    }
  }