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.
private static EntityManagerFactoryMap buildEmFactories(String name, String persistenceUnit){
List
EntityManagerFactoryMap managerFactories = new EntityManagerFactoryMap();
for (DataSourceEntry ds: dsList) {
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.
留言
張貼留言