Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Weaving in Spring problem

I'm trying to use JUnit4 tests with Spring 2.5.5 for my EclipseLink JPA
entities but get the following error:

   java.lang.IllegalStateException: Must start with Java agent to use
InstrumentationLoadTimeWeaver. 

when trying to create the EntityManagerFactory.

I compile and test my code with Maven, and I don't have a full Java EE
container to test things in. Even so, Spring's test framework documentation
says it should work, but does not go far enough into detailing all that is
required. So, by trial-and-error, I came up with the below listed
combination of code, annotations and declarations in which I have eliminated
all the errors but the one related to weaving.

Spring documents weaving when running in Tomcat, but nothing about using the
test framework. Has anyone succeeded in getting Spring 2.5.5, JUnit4 and
EclipseLink JPA to work? I'd be interested in anything anyone has to offer.


My application context for Spring includes the following bean definitions:

<tx:annotation-driven/>
<tx:jta-transaction-manager/>
	
<!-- define the data source -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
	p:url="jdbc:...."
	p:driverClassName="com.sybase.jdbc3.jdbc.SybDriver"
	p:username="blahblah"
	p:password="blahblah"/>
		
<bean id="myEmf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
	<property name="dataSource" ref="dataSource"/>
	<property name="persistenceXmlLocation" value="META-INF/persistence.xml"/>
	<property name="persistenceUnitName" value="myPersistenceUnit"/>
	<property name="jpaVendorAdapter">
	<bean id="jpaAdapter"
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" 
			
p:databasePlatform="org.eclipse.persistence.platform.database.SybasePlatform"
				p:showSql="true"/>
		</property>
		<property name="loadTimeWeaver">
			<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
		</property>
	</bean>
	
	<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">	    
		<property name="entityManagerFactory" ref="myEmf"/>
	</bean>
	
	<!-- bean post-processor for JPA annotations -->
	<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
	
	<bean id="allCodeManager"
class="com.dylt.webManager.ejb.eao.allcode.AllCodeManager" />
	
My persistence.xml is as follows:

<persistence-unit name="myPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
	   <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
	   <mapping-file>META-INF/orm-allcode.xml</mapping-file>
	   <exclude-unlisted-classes/>	  
	</persistence-unit>	
</persistence>

orm-allcode.xml contains the entity declaration:

<entity class="com.dylt.webManager.model.allcode.AllCode" access="FIELD">	      
		<table name="allCodes">
		</table>
		<attributes>
			...
		</attributes>
</entity>	

My Data Access Object is as follows:

public class AllCodeManager extends AllCodeEAO{

       @PersistenceContext(unitName="myPersistenceUnit")
	protected EntityManager em;

	@Override
	public List<AllCode> getAllCodes() {
		Query q = em.createQuery("select ac from AllCode");
                return q.getResultList();
	}	
	
}	

And I have a simple test class for this DAO:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:META-INF/applicationContext-all.xml"})
public class TestAllCodeManager{
	
	@Autowired
	private AllCodeEAO allCodeManager;

	
	@Test
	public void retrieveAllCodeTest(){
		Assert.assertNotNull(this.allCodeManager);
		List<AllCode> list = allCodeEAO.executeQuery("select a from AllCode a",
null);
		Assert.assertNotNull(list);
	}
	
}	

-- 
View this message in context: http://www.nabble.com/Weaving-in-Spring-problem-tp20003299p20003299.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top