Running a separate server is what I did for the past couple of months
whilst developing my web app and, frankly, is a pain :-)
I ran into exactly the same problem and, after searching in vain for a
Jetty-solution, I decided to just address the issue at the root and do
away with the LocalContainerEntityManagerFactoryBean.
I'm using instead a (much more limited)
org.springframework.orm.jpa.LocalEntityManagerFactoryBean.
so my beans.xml has changed to:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="StocksPU"/>
</bean>
<!-- no longer used
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="false" />
<property name="databasePlatform"
value="oracle.toplink.essentials.platform.database.MySQL4Platform" />
</bean>
</property>
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" /
>
</property>
</bean>
-->
this was the original bean def - what I particularly liked was the
fact I could configure the data source from
a properties file, and in fact, I had several of them (prod,
dev and test) all operating on different db's (in fact, the dev
instance was even on a different server altogheter.
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="${jdbc.url}" />
<property name="driverClassName" value="${jdbc.driver}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="testDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="${jdbc.test.url}" />
<property name="driverClassName" value="${jdbc.driver}" />
<property name="username" value="${jdbc.test.username}" />
<property name="password" value="${jdbc.test.password}" />
</bean>
This is now all gone out of the window - the datasource parameters are
configured in META-INF/persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="
http://java.sun.com/xml/ns/persistence"
version="1.0" >
<persistence-unit name="StocksPU" transaction-
type="RESOURCE_LOCAL">
<class>com.g.MyClass</class>
<class>com.g.AnotherClass</class>
<class>...</class>
<properties>
<property name="toplink.jdbc.driver"
value="com.mysql.jdbc.Driver" />
<property name="toplink.jdbc.url"
value="jdbc:mysql://fangorn:3306/stocks_dev" />
<property name="toplink.jdbc.user" value="asif" />
<property name="toplink.jdbc.password" value="blah" />
</properties>
</persistence-unit>
</persistence>
although, I guess I could create several PUs and have a similar
flexibility.
This _seems_ to work just fine (at least, for the very limited testing
I've done).
Not sure how can I get access to the other properties for the
datasource and the vendor adapter, so if anyone has any suggestions,
that would be greatly appreciated.