@SuppressWarnings("rawtypes")
 public EntityManagerFactory createContainerEntityManagerFactory(
     PersistenceUnitInfo info, Map properties) {
   Ejb3Configuration cfg = new Ejb3Configuration();
   if (info instanceof SmartPersistenceUnitInfo) {
     for (String managedPackage : ((SmartPersistenceUnitInfo) info).getManagedPackages()) {
       cfg.addPackage(managedPackage);
     }
   }
   Ejb3Configuration configured = cfg.configure(info, properties);
   return (configured != null ? configured.buildEntityManagerFactory() : null);
 }
 public void configure(Ejb3Configuration cfg) {
   try {
     URL url =
         Thread.currentThread()
             .getContextClassLoader()
             .getResource("mappings/oneToMany/inverseToSuperclass/mappings.hbm.xml");
     cfg.addFile(new File(url.toURI()));
   } catch (URISyntaxException e) {
     throw new RuntimeException(e);
   }
 }
コード例 #3
0
 /**
  * Metodo che permette la persistenza di un'oggetto che mappa un'entita' JPA
  *
  * @param streamObj Oggetto da persistere
  * @param tipoDB Nome dialetto da usare per la persistenza
  * @param configOverrides Map contenente le èroprieta' per la connessione al giusto database
  * @return 1 se l'oggetto e' stato persistito con successo, 0 altrimenti.
  * @throws Throwable
  */
 public static int insertQuery(
     StreamToDbDynamicObject streamObj,
     int tipoDB,
     @SuppressWarnings("rawtypes") Map configOverrides)
     throws Throwable {
   int returnedValue = 0;
   Object o = streamObj.getObject();
   logWriter.warn("QuickDBManager.insertQuery :configOverrides " + configOverrides);
   logWriter.warn(
       "QuickDBManager.insertQuery :object to persist "
           + o.getClass().toString()
           + ", in DB type: "
           + tipoDB);
   EntityManager em = null;
   if (streamObj.getEntityManager() == null) {
     Ejb3Configuration cfg = new Ejb3Configuration();
     cfg.configure("" + tipoDB + "_QuickDBRecognizerPU", configOverrides);
     EntityManagerFactory emf = cfg.addAnnotatedClass(o.getClass()).buildEntityManagerFactory();
     em = emf.createEntityManager();
     streamObj.setEntityManager(em);
   } else {
     em = streamObj.getEntityManager();
   }
   em.getTransaction().begin();
   logWriter.warn("Open Transition");
   try {
     em.merge(o);
     logWriter.warn("Ogetto persistito");
     em.getTransaction().commit();
     returnedValue = 1;
   } catch (Throwable e) {
     em.getTransaction().rollback();
     logWriter.error("DB Rollback " + e);
     throw new Throwable(e.getMessage());
   }
   return returnedValue;
 }
コード例 #4
0
  private static void addTCGClasses(Ejb3Configuration cfg) {
    cfg.addAnnotatedClass(OKey.class);
    cfg.addAnnotatedClass(Operation.class);

    cfg.addAnnotatedClass(View.class);
    cfg.addAnnotatedClass(VHour.class);
    cfg.addAnnotatedClass(VDay.class);
    cfg.addAnnotatedClass(VHostHour.class);
    cfg.addAnnotatedClass(VHostDay.class);

    cfg.addAnnotatedClass(WVHour.class);
    cfg.addAnnotatedClass(WVDay.class);
    cfg.addAnnotatedClass(WVHostHour.class);
    cfg.addAnnotatedClass(WVHostDay.class);
  }
コード例 #5
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(StrTestEntity.class);
   cfg.addAnnotatedClass(SetRefCollEntity.class);
 }
コード例 #6
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(TernaryMapEntity.class);
   cfg.addAnnotatedClass(StrTestEntity.class);
   cfg.addAnnotatedClass(IntTestEntity.class);
 }
コード例 #7
0
  private EntityManagerFactory createFactory() {
    final Ejb3Configuration cfg = new Ejb3Configuration();

    cfg.addProperties(getHibernateProperties());

    cfg.addAnnotatedClass(Action.class);
    cfg.addAnnotatedClass(Browsing.class);
    cfg.addAnnotatedClass(Clip.class);
    cfg.addAnnotatedClass(Comment.class);
    cfg.addAnnotatedClass(Favorite.class);
    cfg.addAnnotatedClass(FavoriteTag.class);
    cfg.addAnnotatedClass(Friend.class);
    cfg.addAnnotatedClass(Host.class);
    cfg.addAnnotatedClass(Message.class);
    cfg.addAnnotatedClass(Rate.class);
    cfg.addAnnotatedClass(Tag.class);
    cfg.addAnnotatedClass(Url.class);

    addTCGClasses(cfg);

    cfg.setDataSource(createDataSource());

    return cfg.buildEntityManagerFactory();
  }
コード例 #8
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(UnversionedStrTestEntity.class);
   cfg.addAnnotatedClass(M2MIndexedListTargetNotAuditedEntity.class);
 }
コード例 #9
0
ファイル: JPAPlugin.java プロジェクト: rnorth-deloitte/play
  @Override
  public void onApplicationStart() {
    if (JPA.entityManagerFactory == null) {
      List<Class> classes = Play.classloader.getAnnotatedClasses(Entity.class);
      if (classes.isEmpty() && Play.configuration.getProperty("jpa.entities", "").equals("")) {
        return;
      }

      final String dataSource = Play.configuration.getProperty("hibernate.connection.datasource");
      if (StringUtils.isEmpty(dataSource) && DB.datasource == null) {
        throw new JPAException(
            "Cannot start a JPA manager without a properly configured database",
            new NullPointerException("No datasource configured"));
      }

      Ejb3Configuration cfg = new Ejb3Configuration();

      if (DB.datasource != null) {
        cfg.setDataSource(DB.datasource);
      }

      if (!Play.configuration
          .getProperty("jpa.ddl", Play.mode.isDev() ? "update" : "none")
          .equals("none")) {
        cfg.setProperty(
            "hibernate.hbm2ddl.auto", Play.configuration.getProperty("jpa.ddl", "update"));
      }

      cfg.setProperty(
          "hibernate.dialect", getDefaultDialect(Play.configuration.getProperty("db.driver")));
      cfg.setProperty("javax.persistence.transaction", "RESOURCE_LOCAL");

      // Explicit SAVE for JPABase is implemented here
      // ~~~~~~
      // We've hacked the org.hibernate.event.def.AbstractFlushingEventListener line 271, to flush
      // collection update,remove,recreation
      // only if the owner will be saved.
      // As is:
      // if (session.getInterceptor().onCollectionUpdate(coll, ce.getLoadedKey())) {
      //      actionQueue.addAction(...);
      // }
      //
      // This is really hacky. We should move to something better than Hibernate like EBEAN
      cfg.setInterceptor(
          new EmptyInterceptor() {

            @Override
            public int[] findDirty(
                Object o,
                Serializable id,
                Object[] arg2,
                Object[] arg3,
                String[] arg4,
                Type[] arg5) {
              if (o instanceof JPABase && !((JPABase) o).willBeSaved) {
                return new int[0];
              }
              return null;
            }

            @Override
            public boolean onCollectionUpdate(Object collection, Serializable key)
                throws CallbackException {
              if (collection instanceof PersistentCollection) {
                Object o = ((PersistentCollection) collection).getOwner();
                if (o instanceof JPABase) {
                  return ((JPABase) o).willBeSaved;
                }
              } else {
                System.out.println("HOO: Case not handled !!!");
              }
              return super.onCollectionUpdate(collection, key);
            }

            @Override
            public boolean onCollectionRecreate(Object collection, Serializable key)
                throws CallbackException {
              if (collection instanceof PersistentCollection) {
                Object o = ((PersistentCollection) collection).getOwner();
                if (o instanceof JPABase) {
                  return ((JPABase) o).willBeSaved;
                }
              } else {
                System.out.println("HOO: Case not handled !!!");
              }
              return super.onCollectionRecreate(collection, key);
            }

            @Override
            public boolean onCollectionRemove(Object collection, Serializable key)
                throws CallbackException {
              if (collection instanceof PersistentCollection) {
                Object o = ((PersistentCollection) collection).getOwner();
                if (o instanceof JPABase) {
                  return ((JPABase) o).willBeSaved;
                }
              } else {
                System.out.println("HOO: Case not handled !!!");
              }
              return super.onCollectionRemove(collection, key);
            }
          });
      if (Play.configuration.getProperty("jpa.debugSQL", "false").equals("true")) {
        org.apache.log4j.Logger.getLogger("org.hibernate.SQL").setLevel(Level.ALL);
      } else {
        org.apache.log4j.Logger.getLogger("org.hibernate.SQL").setLevel(Level.OFF);
      }
      // inject additional  hibernate.* settings declared in Play! configuration
      cfg.addProperties((Properties) Utils.Maps.filterMap(Play.configuration, "^hibernate\\..*"));

      try {
        Field field = cfg.getClass().getDeclaredField("overridenClassLoader");
        field.setAccessible(true);
        field.set(cfg, Play.classloader);
      } catch (Exception e) {
        Logger.error(
            e, "Error trying to override the hibernate classLoader (new hibernate version ???)");
      }
      for (Class<?> clazz : classes) {
        if (clazz.isAnnotationPresent(Entity.class)) {
          cfg.addAnnotatedClass(clazz);
          Logger.trace("JPA Model : %s", clazz);
        }
      }
      String[] moreEntities = Play.configuration.getProperty("jpa.entities", "").split(", ");
      for (String entity : moreEntities) {
        if (entity.trim().equals("")) {
          continue;
        }
        try {
          cfg.addAnnotatedClass(Play.classloader.loadClass(entity));
        } catch (Exception e) {
          Logger.warn("JPA -> Entity not found: %s", entity);
        }
      }
      for (ApplicationClass applicationClass : Play.classes.all()) {
        if (applicationClass.isClass() || applicationClass.javaPackage == null) {
          continue;
        }
        Package p = applicationClass.javaPackage;
        Logger.info("JPA -> Adding package: %s", p.getName());
        cfg.addPackage(p.getName());
      }
      String mappingFile = Play.configuration.getProperty("jpa.mapping-file", "");
      if (mappingFile != null && mappingFile.length() > 0) {
        cfg.addResource(mappingFile);
      }
      Logger.trace("Initializing JPA ...");
      try {
        JPA.entityManagerFactory = cfg.buildEntityManagerFactory();
      } catch (PersistenceException e) {
        throw new JPAException(e.getMessage(), e.getCause() != null ? e.getCause() : e);
      }
      JPQL.instance = new JPQL();
    }
  }
コード例 #10
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(BiRefEdEntity.class);
   cfg.addAnnotatedClass(BiRefIngEntity.class);
 }
コード例 #11
0
  @SuppressWarnings("unchecked")
  @Override
  public void onApplicationStart() {
    //
    //	NOTE: this uses the JPA class to store the request's entityManagerFactory.
    //	The trick is that the MJPAPlugin has higher priority than Play's native JPAPlugin.
    //
    if (JPA.entityManagerFactory == null) {
      List<Class> classes = Play.classloader.getAnnotatedClasses(Entity.class);
      if (classes.isEmpty() && Play.configuration.getProperty("jpa.entities", "").equals("")) {
        return;
      }
      if (MDB.datasources == null || MDB.datasources.isEmpty()) {
        if (Play.configuration.getProperty("mjpa.runWithNoDB", "").equals("true")) {
          //
          //	Create a dummy entity manager factory, so that JPA is prevented from screaming.
          //
          JPA.entityManagerFactory = getDummyFactory();
          log.info(
              "No properly configured databases found.  JPA will not be initialized until databases are added");
        } else {
          throw new JPAException(
              "Cannot start a MJPA manager without a properly configured database",
              new NullPointerException("No datasource configured"));
        }
      } else {
        //
        //	Iterate over the datasources and build a configuration for each.
        //
        for (Entry<String, DataSource> entry : MDB.datasources.entrySet()) {
          ComboPooledDataSource datasource = (ComboPooledDataSource) entry.getValue();

          Ejb3Configuration cfg = buildEjbConfiguration(classes, datasource);
          Logger.trace("Initializing JPA ...");
          try {
            EntityManagerFactory factory = cfg.buildEntityManagerFactory();
            JPA.entityManagerFactory = factory;
            factoryMap.put(entry.getKey(), factory);
            log.debug("Added datasource: " + datasource.getJdbcUrl());
          } catch (PersistenceException e) {
            throw new JPAException(e.getMessage(), e.getCause() != null ? e.getCause() : e);
          }
        }
      }
      JPQLDialect.instance = new JPQLDialect();
    }

    //
    //	Set up the key extractor here, by looking for an application class that implements it.
    //
    List<Class> extractors = Play.classloader.getAssignableClasses(RequestDBKeyExtractor.class);
    if (extractors.size() > 1) {
      throw new JPAException(
          "Too many DB Key extract classes.  "
              + "The Multiple DB plugin must use a single extractor class to "
              + "specify its extractor.  These classes where found: "
              + extractors);
    } else if (!extractors.isEmpty()) {
      Class clazz = extractors.get(0);
      try {
        keyExtractor = (RequestDBKeyExtractor) clazz.newInstance();
      } catch (InstantiationException e) {
        log.error("Unable to instantiate extractor class:", e);
      } catch (IllegalAccessException e) {
        log.error("Invalid access to extractor class:", e);
      }
      log.debug("Using application DB key extractor class: " + keyExtractor.getClass().getName());
    } else {
      log.debug("Using default DB key extractor class: " + keyExtractor.getClass().getName());
    }
  }
コード例 #12
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(JoinEmbIdNamingRefEdEntity.class);
   cfg.addAnnotatedClass(JoinEmbIdNamingRefIngEntity.class);
 }
コード例 #13
0
ファイル: Delete.java プロジェクト: ksdj/cs-studio-thirdparty
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(BasicTestEntity2.class);
 }
コード例 #14
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(PropertyAccessTypeEntity.class);
 }
コード例 #15
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(DoubleListJoinColumnBidirectionalRefIngEntity.class);
   cfg.addAnnotatedClass(DoubleListJoinColumnBidirectionalRefEdEntity1.class);
   cfg.addAnnotatedClass(DoubleListJoinColumnBidirectionalRefEdEntity2.class);
 }
コード例 #16
0
  /**
   * @param classes
   * @param datasource
   * @return
   */
  @SuppressWarnings("unchecked")
  public static Ejb3Configuration buildEjbConfiguration(
      List<Class> classes, ComboPooledDataSource datasource) {
    Ejb3Configuration cfg = new Ejb3Configuration();
    cfg.setDataSource(datasource);
    if (!Play.configuration.getProperty("jpa.ddl", "update").equals("none")) {
      cfg.setProperty(
          "hibernate.hbm2ddl.auto", Play.configuration.getProperty("jpa.ddl", "update"));
    }
    cfg.setProperty("hibernate.dialect", getDefaultDialect(datasource.getDriverClass()));
    cfg.setProperty("javax.persistence.transaction", "RESOURCE_LOCAL");

    // Explicit SAVE for JPASupport is implemented here
    // ~~~~~~
    // We've hacked the org.hibernate.event.def.AbstractFlushingEventListener line
    // 271, to flush collection update,remove,recreation
    // only if the owner will be saved.
    // As is:
    // if (session.getInterceptor().onCollectionUpdate(coll, ce.getLoadedKey())) {
    // actionQueue.addAction(...);
    // }
    //
    // This is really hacky. We should move to something better than Hibernate
    // like EBEAN
    cfg.setInterceptor(
        new EmptyInterceptor() {
          /** Generated GUID for serialization support. */
          private static final long serialVersionUID = -8670026536584880961L;

          @Override
          public int[] findDirty(
              Object o, Serializable id, Object[] arg2, Object[] arg3, String[] arg4, Type[] arg5) {
            if (o instanceof JPASupport && !((JPASupport) o).willBeSaved) {
              return new int[0];
            }
            return null;
          }

          @Override
          public boolean onCollectionUpdate(Object collection, Serializable key)
              throws CallbackException {
            if (collection instanceof PersistentCollection) {
              Object o = ((PersistentCollection) collection).getOwner();
              if (o instanceof JPASupport) {
                return ((JPASupport) o).willBeSaved;
              }
            } else {
              System.out.println("HOO: Case not handled !!!");
            }
            return super.onCollectionUpdate(collection, key);
          }

          @Override
          public boolean onCollectionRecreate(Object collection, Serializable key)
              throws CallbackException {
            if (collection instanceof PersistentCollection) {
              Object o = ((PersistentCollection) collection).getOwner();
              if (o instanceof JPASupport) {
                return ((JPASupport) o).willBeSaved;
              }
            } else {
              System.out.println("HOO: Case not handled !!!");
            }
            return super.onCollectionRecreate(collection, key);
          }

          @Override
          public boolean onCollectionRemove(Object collection, Serializable key)
              throws CallbackException {
            if (collection instanceof PersistentCollection) {
              Object o = ((PersistentCollection) collection).getOwner();
              if (o instanceof JPASupport) {
                return ((JPASupport) o).willBeSaved;
              }
            } else {
              System.out.println("HOO: Case not handled !!!");
            }
            return super.onCollectionRemove(collection, key);
          }
        });
    if (Play.configuration.getProperty("jpa.debugSQL", "false").equals("true")) {
      org.apache.log4j.Logger.getLogger("org.hibernate.SQL").setLevel(Level.ALL);
    } else {
      org.apache.log4j.Logger.getLogger("org.hibernate.SQL").setLevel(Level.OFF);
    }
    // inject additional hibernate.* settings declared in Play! configuration
    cfg.addProperties((Properties) Utils.Maps.filterMap(Play.configuration, "^hibernate\\..*"));

    try {
      Field field = cfg.getClass().getDeclaredField("overridenClassLoader");
      field.setAccessible(true);
      field.set(cfg, Play.classloader);
    } catch (Exception e) {
      Logger.error(
          e, "Error trying to override the hibernate classLoader (new hibernate version ???)");
    }
    for (Class<? extends Annotation> clazz : classes) {
      if (clazz.isAnnotationPresent(Entity.class)) {
        cfg.addAnnotatedClass(clazz);
        Logger.trace("JPA Model : %s", clazz);
      }
    }
    String[] moreEntities = Play.configuration.getProperty("jpa.entities", "").split(", ");
    for (String entity : moreEntities) {
      if (entity.trim().equals("")) continue;
      try {
        if (Play.classes.getApplicationClass(entity) == null) {
          cfg.addAnnotatedClass(Play.classloader.loadClass(entity));
        } else {
          cfg.addAnnotatedClass(Play.classes.getApplicationClass(entity).javaClass);
        }

      } catch (Exception e) {
        Logger.warn("JPA -> Entity not found: %s", entity);
      }
    }
    return cfg;
  }
コード例 #17
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(AuditedMethodMappedSuperclass.class);
   cfg.addAnnotatedClass(AuditedAllSubclassEntity.class);
   cfg.addAnnotatedClass(NotAuditedSubclassEntity.class);
 }
コード例 #18
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(NotAuditedManyToOneComponentTestEntity.class);
   cfg.addAnnotatedClass(UnversionedStrTestEntity.class);
 }
コード例 #19
0
 @Override
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(ClassTypeEntity.class);
   cfg.addAnnotatedClass(ParentEntity.class);
   cfg.addAnnotatedClass(ChildEntity.class);
 }
コード例 #20
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(SetRefEdMulIdEntity.class);
   cfg.addAnnotatedClass(SetRefIngMulIdEntity.class);
 }
コード例 #21
0
ファイル: JPAPlugin.java プロジェクト: visan/play1
  @Override
  public void onApplicationStart() {

    // must check and configure JPA for each DBConfig
    for (DBConfig dbConfig : DB.getDBConfigs()) {
      // check and enable JPA on this config

      // is JPA already configured?
      String configName = dbConfig.getDBConfigName();

      if (JPA.getJPAConfig(configName, true) == null) {
        // must configure it

        // resolve prefix for hibernate config..
        // should be nothing for default, and db_<name> for others
        String propPrefix = "";
        if (!DBConfig.defaultDbConfigName.equalsIgnoreCase(configName)) {
          propPrefix = "db_" + configName + ".";
        }
        List<Class> classes = findEntityClassesForThisConfig(configName, propPrefix);
        if (classes == null) continue;

        // we're ready to configure this instance of JPA
        final String hibernateDataSource =
            Play.configuration.getProperty(propPrefix + "hibernate.connection.datasource");

        if (StringUtils.isEmpty(hibernateDataSource) && dbConfig == null) {
          throw new JPAException(
              "Cannot start a JPA manager without a properly configured database"
                  + getConfigInfoString(configName),
              new NullPointerException("No datasource configured"));
        }

        Ejb3Configuration cfg = new Ejb3Configuration();

        if (dbConfig.getDatasource() != null) {
          cfg.setDataSource(dbConfig.getDatasource());
        }

        if (!Play.configuration
            .getProperty(propPrefix + "jpa.ddl", Play.mode.isDev() ? "update" : "none")
            .equals("none")) {
          cfg.setProperty(
              "hibernate.hbm2ddl.auto",
              Play.configuration.getProperty(propPrefix + "jpa.ddl", "update"));
        }

        String driver = null;
        if (StringUtils.isEmpty(propPrefix)) {
          driver = Play.configuration.getProperty("db.driver");
        } else {
          driver = Play.configuration.getProperty(propPrefix + "driver");
        }
        cfg.setProperty("hibernate.dialect", getDefaultDialect(propPrefix, driver));
        cfg.setProperty("javax.persistence.transaction", "RESOURCE_LOCAL");

        cfg.setInterceptor(new PlayInterceptor());

        // This setting is global for all JPAs - only configure if configuring default JPA
        if (StringUtils.isEmpty(propPrefix)) {
          if (Play.configuration.getProperty(propPrefix + "jpa.debugSQL", "false").equals("true")) {
            org.apache.log4j.Logger.getLogger("org.hibernate.SQL").setLevel(Level.ALL);
          } else {
            org.apache.log4j.Logger.getLogger("org.hibernate.SQL").setLevel(Level.OFF);
          }
        }
        // inject additional  hibernate.* settings declared in Play! configuration
        Properties additionalProperties =
            (Properties)
                Utils.Maps.filterMap(Play.configuration, "^" + propPrefix + "hibernate\\..*");
        // We must remove prefix from names
        Properties transformedAdditionalProperties = new Properties();
        for (Map.Entry<Object, Object> entry : additionalProperties.entrySet()) {
          Object key = entry.getKey();
          if (!StringUtils.isEmpty(propPrefix)) {
            key = ((String) key).substring(propPrefix.length()); // chop off the prefix
          }
          transformedAdditionalProperties.put(key, entry.getValue());
        }
        cfg.addProperties(transformedAdditionalProperties);

        try {
          // nice hacking :) I like it..
          Field field = cfg.getClass().getDeclaredField("overridenClassLoader");
          field.setAccessible(true);
          field.set(cfg, Play.classloader);
        } catch (Exception e) {
          Logger.error(
              e, "Error trying to override the hibernate classLoader (new hibernate version ???)");
        }

        for (Class<?> clazz : classes) {
          cfg.addAnnotatedClass(clazz);
          if (Logger.isTraceEnabled()) {
            Logger.trace("JPA Model : %s", clazz);
          }
        }
        String[] moreEntities =
            Play.configuration.getProperty(propPrefix + "jpa.entities", "").split(", ");
        for (String entity : moreEntities) {
          if (entity.trim().equals("")) {
            continue;
          }
          try {
            cfg.addAnnotatedClass(Play.classloader.loadClass(entity));
          } catch (Exception e) {
            Logger.warn("JPA -> Entity not found: %s", entity);
          }
        }

        for (ApplicationClass applicationClass : Play.classes.all()) {
          if (applicationClass.isClass() || applicationClass.javaPackage == null) {
            continue;
          }
          Package p = applicationClass.javaPackage;
          Logger.info("JPA -> Adding package: %s", p.getName());
          cfg.addPackage(p.getName());
        }

        String mappingFile = Play.configuration.getProperty(propPrefix + "jpa.mapping-file", "");
        if (mappingFile != null && mappingFile.length() > 0) {
          cfg.addResource(mappingFile);
        }

        if (Logger.isTraceEnabled()) {
          Logger.trace("Initializing JPA" + getConfigInfoString(configName) + " ...");
        }

        try {
          JPA.addConfiguration(configName, cfg);
        } catch (PersistenceException e) {
          throw new JPAException(
              e.getMessage() + getConfigInfoString(configName),
              e.getCause() != null ? e.getCause() : e);
        }
      }
    }

    // must look for Entity-objects referring to none-existing JPAConfig
    List<Class> allEntityClasses = Play.classloader.getAnnotatedClasses(Entity.class);
    for (Class clazz : allEntityClasses) {
      String configName = Entity2JPAConfigResolver.getJPAConfigNameForEntityClass(clazz);
      if (JPA.getJPAConfig(configName, true) == null) {
        throw new JPAException(
            "Found Entity-class ("
                + clazz.getName()
                + ") referring to none-existing JPAConfig"
                + getConfigInfoString(configName)
                + ". "
                + "Is JPA properly configured?");
      }
    }
  }
コード例 #22
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(Address.class);
   cfg.addAnnotatedClass(Contact.class);
   cfg.addAnnotatedClass(PersonalContact.class);
 }
コード例 #23
0
 @Override
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(Staff.class);
 }
コード例 #24
0
 public void configure(Ejb3Configuration cfg) {
   cfg.addAnnotatedClass(ManyToOneNotInsertableEntity.class);
   cfg.addAnnotatedClass(NotInsertableEntityType.class);
 }