Skip to main content


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] Tue, 25 February 2014 02:55 Go to next message
yuan yao is currently offline yuan yaoFriend
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] Tue, 25 February 2014 03:12 Go to previous message
Shaun Smith is currently offline Shaun SmithFriend
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: Thu Apr 25 18:14:41 GMT 2024

Powered by FUDForum. Page generated in 0.02883 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top