Hi,
I'm new to Spring and trying to evaluate a JPA-based data access setup with not much success. The goal is to create a simple Spring 2.5.x configuration with JPA using Eclipselink as the implementation. The setup should be deployable to Tomcat (or any web container, Glassfish and Tomcat are the to servers preferred), and I need Spring/Eclipselink to generate the tables (and/or the SQL scripts) for the entities (as a regular EJB3 deployment would).
The result is that the app is deployable but on Tomcat, nothing happens to the database. On GF, the default JDBC pool from JNDI (named jdbc/__default) is used to find the database and create the tables, so possibly something's wrong with the classloading and weaving I guess because it's a GF default behavior.
I know I'm screwing up something, I just have no clue what
What I did is the following:
created a WEB-INF/applicationContext.xml with the followin contents:
Code:<beans...> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql:localhost:3306/springtest" /> <property name="username" value="springtest" /> <property name="password" value="pass" /> </bean> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"> <property name="databasePlatform" value="org.eclipse.persistence.platform.database.MySQLPlatform" /> <property name="generateDdl" value="true" /> <property name="showSql" value="true" /> <property name="jpaDialect"> <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" /> </property> <property name="persistenceProvider"> <bean class="org.eclipse.persistence.jpa.PersistenceProvider" /> </property> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="jpaVendorAdapter" ref="jpaVendorAdapter" /> <property name="persistenceXmlLocation" value="META-INF/persistence.xml" /> <property name="persistenceUnitName" value="myPU" /> <property name="loadTimeWeaver"> <bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver" /> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <tx:annotation-driven mode="aspectj" /> <tx:jta-transaction-manager /> <context:annotation-config /> <context:load-time-weaver aspectj-weaving="on" /> <context:component-scan base-package="org.springtest" /> </beans>
modified META-INF/context.xml for Tomcat:
and also placed spring-tomcat-weaver.jar in tomcat's lib/ folder, and also added -Djavaagent="c:/program files/tomcat/lib/spring-agent.jar" to the Tomcat JAVA_OPTs (I hope Tomcat finds itCode:<?xml version="1.0" encoding="UTF-8"?> <Context antiJARLocking="true" path="/testapp"> <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" /> </Context>)
Let's assume that the app correctly deploys to the /testapp context (it does).
created one TestEntity:
created one META-INF/persistence.xml in the classpath (assembled to WEB-INF/classes/META-INF/persistence.xmlCode:package org.springtest.domain; import ... @Entity public class TestEntity implements Serializable { ... }
And now I'm waiting for the magic to happen. Any ideas, hints, where to start debugging?Code:<persistence ...> <persistence-unit name="myPU" transaction-type="RESOURCE_LOCAL"> <properties> <property name="eclipselink.ddl-generation" value="create-tables"/> </properties> </persistence-unit> </persistence>
Thanks a lot, folks!



Reply With Quote
