Programmatic EntityManager

Instead of you dependence Injection for EntityManager by annotation, you can also adopt programmatic EntityManager by the following code.

private static EntityManagerFactoryMap buildEmFactories(String name, String persistenceUnit){
       
        List dsList =  CsvConfigManager.getReprintConfig(name).getDataSourceList();
        EntityManagerFactoryMap managerFactories = new EntityManagerFactoryMap();
        for (DataSourceEntry ds: dsList) {
            HashMap property = new HashMap();
            property.put(TRANSACTION_TYPE, "JTA");
            property.put(JTA_DATASOURCE, ds.getJndi());
            property.put(CACHE_TYPE_DEFAULT, "NONE");
            property.put(CACHE_SHARED_DEFAULT, "false");
            property.put(WEAVING_INTERNAL, "false");
            property.put(SESSION_NAME, ds.getJndi());
            property.put(LOGGING_SESSION, "false");
            property.put(CATEGORY_LOGGING_LEVEL_, "WARNING");

            EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, property);
            managerFactories.get().put(ds.getJndi(), emf);
        }
       
        return managerFactories;
       
    }


If you encountered exception like: Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. please be sure that the TRANSACTION_TYPE is "JTA" rather than "RESOURCE_LOCAL". If the transaction is "RESOURCE_LOCAL", server will ignore the JTA_DATASOURCE setting. Therefore no information can be retrieved from the data source that set on the weblogic.

留言

這個網誌中的熱門文章

Disable ionic's sidemenu content drag to toggle menu

Multiple writable mappings exist for the field. Only one may be defined as writable, all others must be specified read-only.

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser