I have been looking for this for the past few hours, maybe some of you can help me.
I am trying to reload matching information in EntityManagerFactory (or SessionFactory) at runtime in spring
EntityManagerFactory is defined as follows:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceXmlLocation" value="persistence.xml" /> <property name="persistenceUnitName" value="JPAService" /> <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/> <property name="dataSource" ref="dataSource" /> <property name="jpaDialect"> <bean class="org.springframework.orm.jpa.vendor.Hibernate.JpaDialect" /> </property> <property name="jpaProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.hbm2ddl.auto">none</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean>
In my persistence.xml, I just define jar where the mapping files are
<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="JPAService" transaction-type="RESOURCE_LOCAL"> <jar-file>WEB-INF/lib/mapping.jar</jar-file> </persistence-unit> </persistence>
My hibernation mapping files will change very often, and my application uses these files to create part of the user interface. Therefore, I do not want to restart the server every time I change my sleep mappings.
One thing I was thinking about is replacing EntityManagerFacotries / SessionFactory with a new one, e.g.
Hibernate Runtime Configuration
Dynamic EJB Tuning
but I do not know the side effects
Another way is to change (add / remove) EntityManagerFactory / SessionFactory Mapping programmatically at runtime:
JPA: adding objects to EntityManagerFactory programmatically
Programmatically load Entity classes with JPA 2.0?
A very complex scenario in which no solution was found
Dynamically creating an ORM entity class - NOT SOLVED
Another lead mentions dynamic JPA
How can I combine / extend continuity units from different JARs?
JPA 2.0: adding entity classes to PersistenceUnit * from different jar * automatically
I already tried to update the whole application context from spring so
@RequestMapping(value = { "/path" }) public ModelMap refresh(Model model, Locale locale) throws IOException, TemplateException, ExtJSException { ((ConfigurableApplicationContext)ApplicationContextProvider.getApplicationContext()).refresh(); return getMessage("Context was refreshed!!"); }
But it looks like this project is no longer supported ...