Hello,

I am currently trying to override the settings in the persistence.xml 
dynamically with my own hashmap. The background is, that I want to change the 
datasource dynamically depending on where to persist the Entity. 

Unfortunatley the factory does not seem to care for any values, that I am 
trying to override. Did I miss anything?

My current code is as follows:


  | @Stateless
  | public class EJB3CampaignDAO extends EJB3BaseDAO implements CampaignDAO {
  | 
  |   @PersistenceUnit(unitName="testPersdb")
  |   EntityManagerFactory emf; 
  | 
  | .....
  | 
  |   public datacontainer.Campaign findSingleCampaign ( int id) {
  |       
  |       java.util.Map configOverride = new HashMap();
  |       configOverride.put("javax.persistence.provider", 
"org.hibernate.ejb.HibernatePersistence");
  |       configOverride.put("javax.persistence.transactionType", "JTA");
  |       configOverride.put("javax.persistence.jtaDataSource", 
"anotherDatasource_ccDS");
  |       
  |       EntityManager manager = emf.createEntityManager(configOverride);
  | 

And my persistence.xml looks like this


  | <?xml version="1.0" encoding="UTF-8"?>
  | 
  | <persistence>
  |    <persistence-unit name="testPersdb" transaction-type="JTA">
  |        <provider>org.hibernate.ejb.HibernatePersistence</provider>
  |        <jta-data-source>java:/aDatasource_ccDS</jta-data-source>
  |        <class>persistence.ejb3.entity.EJB3Campaign</class>
  |    </persistence-unit>
  | </persistence>
  | 

If I´m trying to override the setting while creating the EntityManagerFactory I 
get a very unexpected ClassCastException. So this way does not seem to work 
either


  | @Stateless
  | public class EJB3CampaignDAO extends EJB3BaseDAO implements CampaignDAO {
  | 
  |   @PersistenceContext(unitName="testPersdb")  
  |   private EntityManager manager;
  |   public datacontainer.Campaign findSingleCampaign ( int id) {
  |       System.out.println("findSingleCampaign " + id);
  |       
  |       java.util.Map configOverride = new HashMap();
  |       configOverride.put("javax.persistence.provider", 
"org.hibernate.ejb.HibernatePersistence");
  |       configOverride.put("javax.persistence.transactionType", "JTA");
  |       configOverride.put("javax.persistence.jtaDataSource", 
"anotherDatasource_ccDS");
  |    EntityManagerFactory emf = 
Persistence.createEntityManagerFactory("testPersdb", configOverride);
  |       emf = Persistence.createEntityManagerFactory("testPersdb", 
configOverride);
  |       
  |     manager = emf.createEntityManager();
  | 

This is how the Exception looks like

  | javax.ejb.EJBTransactionRolledbackException: 
javax.persistence.PersistenceException: java.lang.ClassCastException: 
java.lang.String; nested exception is: javax.persistence.PersistenceException: 
java.lang.ClassCastException: java.lang.String
  | javax.persistence.PersistenceException: java.lang.ClassCastException: 
java.lang.String
  |         at 
org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:188)
  |         at 
org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:110)
  |         at 
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
  | 

Is there anything wrong in the code or am I thinking totally wrong? Or is this 
just a bug in the JBOSS EJB3-Implementation?

Any help is greatly appriciated

THank you

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3943145#3943145

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3943145


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to