[jboss-user] [EJB 3.0] - Updating EntityManagerFactory

cmlopezalv do-not-reply at jboss.com
Mon Jul 10 19:33:52 EDT 2006


My application is creating entity beans dynamically, so, when i create i new entity bean i must update the Ejb3Configuration to let it know there is a new bean, i make this using the method 'addAnnotatedClass(Class clazz)' and 'buildMappings()'.  

I have several EntityManagerFactory, created using the clas Ejb3Configuration , using the method (createEntityManagerFactory()).

The problem is how to update the EntityManagerFactory that has been already created, before the update of the Ejb3Copnfiguration.

If i want to do it, i have to create a new EntityManagerFactory from the Ejb3Configuration updated.


Ejb3Configuration ejb3Configuration = new Ejb3Configuration();
Properties p = new Properties();
//Config properties .......
//add some entities
//Create the factory
EntityManagerFactory factory = ejbConfiguration.createEntityManagerFactory();
Then in some point my application needs to know about a new entity bean
so i add it to the configuration i've been using:


EntityManager entityManager = factory.createEntityManagerFactory();
//Use this EntityManager to persist the new entity
entityManager.persist([instance of EntityBean3]);

In this point i got the error: EntityBean3 not mapped, that is because the factory is not  synchronized with the Ejb3Configuration.

How can i make this sync ?.   I'm working creating a new EntityManagerFactory everytime the application generates a new entity bean, but i think that is really ugly, not to mention the performance problems for the application.

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

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

More information about the jboss-user mailing list