Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Reload Persistence Unit at Runtime
icon5.gif  Reload Persistence Unit at Runtime [message #1256027] Mon, 24 February 2014 21:55 Go to next message
yuan yao is currently offline yuan yao
Messages: 6
Registered: February 2014
Junior Member
Could I reload persistence unit at runtime?
For example, I add some new mappings and I want them to take effect immediately, without restart of the app.

Specially, I use Spring with JPA.
    <bean id="emf" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="cms" />

        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
                <property name="database" value="MYSQL" />
            </bean>
        </property>
        <property name="jpaDialect">
            <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />
        </property>

        <property name="jpaPropertyMap">
            <map>
                <entry key="eclipselink.classloader" value-ref="dynamicClassLoader"></entry>
            </map>
        </property>
    </bean>
Re: Reload Persistence Unit at Runtime [message #1256037 is a reply to message #1256027] Mon, 24 February 2014 22:12 Go to previous message
Shaun Smith is currently offline Shaun Smith
Messages: 197
Registered: July 2009
Senior Member
The EclipseLink JpaEntityManagerFactory class that implements EntityManagerFactory allows you to force metadata to be refreshed: http://www.eclipse.org/eclipselink/api/2.3/org/eclipse/persistence/jpa/JpaEntityManagerFactory.html#refreshMetadata. Note that once refreshed new EntityManagers are based on the new metadata but existing EMs and in flight transactions are unaffected. This allows for a hot upgrade of metadata without requiring an application restart or reboot.

I can't comment on how Spring's wrappers will or will not allow you to leverage this method but you can see it in action in the LeagueRepository class in the MySports example: https://wiki.eclipse.org/EclipseLink/Examples/MySports

--Shaun
Previous Topic:Error obtaining the Transaction Manager
Next Topic:Changing lazy attributes when shared cache disabled
Goto Forum:
  


Current Time: Fri Jul 25 23:06:01 EDT 2014

Powered by FUDForum. Page generated in 0.06216 seconds