Transaction problem with JPA2-spring-Hibernate - spring

Hi I got a problem with the above integration of the frameworks.
I'm using JPA2 in a maven configuration with the library versions:
Spring 3.0.5
Hibernate 3.5.4
Hibernate-jpa-2.0-api-1.0.0.Final
I'm using the persistence.xml:
<persistence-unit name="AccountingPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.westernacher.wps.bnotk.fibu.domain.BaseEntity</class>
<class>com.westernacher.wps.bnotk.fibu.domain.AccountSettings</class>
<!-- This is not any more necessary, it will be done in spring config.
<properties>
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml"/>
</properties> -->
</persistence-unit>
and the applicationContext.xml:
<context:annotation-config />
<context:component-scan base-package="com.westernacher.wps.bnotk.fibu.dao" />
<context:component-scan base-package="com.westernacher.wps.bnotk.fibu.service" />
<tx:annotation-driven transaction-manager="txManager"
proxy-target-class="false"
mode="proxy" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource">
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${dataSource.driverClassName}" p:url="${dataSource.url}"
p:username="${dataSource.username}" p:password="${dataSource.password}" />
<context:property-placeholder location="classpath:datasource.properties" />
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
The class AccountSettingsDaoImpl is annotated with #Repository.
The methods for database access in this class are marked with #Transactional:
#Transactional(readOnly=false)
public void save(E entity) {
// entityManager.merge(entity);
// entityManager.flush();
entityManager.persist(entity);
}
The Test class is the following:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration("/applicationContext.xml")
public class AccountSettingsDaoImplTest {
#Resource
private AccountSettingsDaoImpl accountSettingsDaoImpl;
private final static Long id=1L;
#Test
public void testSave() throws Exception {
AccountSettings accountSettings = new AccountSettings();
accountSettings.setCategory("A");
accountSettings.setDescription("adlkjsadhad asdlkasdkjahsdlkashd ");
accountSettingsDaoImpl.save(accountSettings);
Long localId = accountSettings.getId();
System.out.println("id="+localId);
}
}
But running my JUnit-Tests, I will get the following exception:
29.07.2011 18:46:01 org.springframework.test.context.TestContextManager prepareTestInstance
SCHWERWIEGEND: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener#127e942f] to prepare test instance [com.westernacher.wps.bnotk.fibu.dao.AccountSettingsDaoImplTest#6b9c18ae]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.westernacher.wps.bnotk.fibu.dao.AccountSettingsDaoImplTest': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'accountSettingsDaoImpl' must be of type [com.westernacher.wps.bnotk.fibu.dao.AccountSettingsDaoImpl], but was actually of type [$Proxy23]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:374)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'accountSettingsDaoImpl' must be of type [com.westernacher.wps.bnotk.fibu.dao.AccountSettingsDaoImpl], but was actually of type [$Proxy23]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:349)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:435)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:409)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:541)
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:297)
... 26 more
29.07.2011 18:46:01 org.springframework.context.support.AbstractApplicationContext doClose
Can anyone help me?
Best Regards, Daniel

You can't inject proxies by concrete type (if they are made by interface) - you should use the interface instead:
#Inject
private AccountSettingsDao accountSettingsDao;

Related

Spring Batch - Sporadic issues with Custom FileItemWriter

We have multiple jobs running in Linux environment where jobs run in parallel. We process files with multi-hundred thousands of records in each of these batches. Following is our job steps.xml. This job runs daily but it fails sporadically. It runs 95% of times without any issues but when it fails it fails with below error. Can someone please check what is wrong with our configuration and tell how to address this?
Error:
"org.springframework.batch.item.ItemStreamException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.com.xxx.xx.batchsync.BatchsyncExtractFileItemWriter': Initialization of bean failed; nested exception is java.lang.IllegalStateException: **Not allowed to access field 'outputFile2': java.lang.IllegalAccessException: Class org.springframework.batch.core.jsr.launch.support.BatchPropertyBeanPostProcessor$1 can not access a member of class com.xxx.xx.std.StdFileItemWriter with modifiers "private"**
at org.springframework.batch.jsr.item.CheckpointSupport.open(CheckpointSupport.java:65)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:197)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.jsr.job.flow.support.state.JsrStepState.handle(JsrStepState.java:53)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.jsr.job.flow.JsrFlowJob.doExecute(JsrFlowJob.java:82)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
at org.springframework.batch.core.jsr.launch.JsrJobOperator$2.run(JsrJobOperator.java:675)
at java.lang.Thread.run(Thread.java:809)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.com.xxx.xx.batchsync.BatchsyncExtractFileItemWriter': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Not allowed to access field 'outputFile2': java.lang.IllegalAccessException: Class org.springframework.batch.core.jsr.launch.support.BatchPropertyBeanPostProcessor$1 can not access a member of class com.xxx.xx.std.StdFileItemWriter with modifiers "private"
at org.springframework.beans.factory.support.AbstractAutowireCapa"
Steps.xml:
enter code here
<step id="#{jobParameters['STEPNAME']}-Step1">
<properties>
<property name="JOB_FILE_NAME" value="BatchsyncExtract"/>
<property name="JOBNAME" value="#{jobParameters['JOBNAME']}"/>
<property name="STEPNAME" value="#{jobParameters['STEPNAME']}"/>
<property name="APPL" value="#{jobParameters['APPL']}"/>
<property name="BANK" value="#{jobParameters['BANK']}"/>
<property name="ODATE" value="#{jobParameters['ODATE']}"/>
<property name="PREVENT_JOB_RESTART" value="#{jobParameters['PREVENT_JOB_RESTART']}"/>
<property name="BATCH_ROOT" value="#{jobParameters['BATCH_ROOT']}"/>
<property name="WSBATCH_HOME" value="#{jobParameters['WSBATCH_HOME']}"/>
<property name="BATCH_LOG_FOLDER" value="#{jobParameters['BATCH_ROOT']}/batch/logs"/>
<property name="BUSINESS_MAIN" value="com.xxx.xx.BatchsyncExtractBusinessmain"/>
<property name="PROGRAM_NAME" value="IV-IpBatchsyncExtract"/>
<property name="TODAY" value="#{jobParameters['TODAY']}"/>
....
<property name="PARTITION" value="#{jobParameters['WSBATCH_HOME']}/partinfo/BatchsyncExtract_LdbidIpIdPartition_#{jobParameters['BANK']}.xml"/>
<property name="CHUNKSIZE" value="#{jobParameters['CHUNKSIZE']}" />
</properties>
<listeners>
<listener ref="com.xxx.xx.std.StdStepListener">
</listener>
<listener ref="com.xxx.xx.std.StdChunkListener">
</listener>
</listeners>
<chunk checkpoint-policy="custom" >
<reader ref="com.xxx.xx.BatchsyncExtractInputBDS">
</reader>
<processor ref="com.xxx.xx.std.StdJobStepCursorBased"/>
<writer ref="com.xxx.xx.BatchsyncExtractFileItemWriter">
<properties>
<property name="outputFile1" value="#{jobParameters['BATCH_ROOT']}/batch/import/#{jobParameters['APPL']}/batchsync_extract_#{jobParameters['BANK']}_#{jobParameters['ODATE']}_#{jobParameters['RUN']};default;default" />
<property name="outputFile2" value="#{jobParameters['BATCH_ROOT']}/batch/import/#{jobParameters['APPL']}/batchsync_extract_totals_#{jobParameters['BANK']}_#{jobParameters['ODATE']}_#{jobParameters['RUN']};default;default" />
</properties>
</writer>
<checkpoint-algorithm ref="com.xxx.xx.batch.utils.CustomCheckPointAlgoritmn">
<properties>
<property name="chunkSize" value="#{jobParameters['CHUNKSIZE']}" />
<!--property name="timeInterval" value="#{jobParameters['TIMEINTERVAL']}" /-->
</properties>
</checkpoint-algorithm>
</chunk>
</step>

Illegal attempt to enlist multiple 1PC XAResources

We have Multiple Transaction Managers (WebsphereUOWTransactionManager and DatasourceTransactionManager) and use Mybatis and NamedParameterJdbcTemplate (legacy code)
The code used to work and the changes made are to move #Transactional to the Service Level and remove sqlsession.commit from the mybatis code.
But now there is an issue where the legacy code (JdbcTemplate) is executed.
The error is
20170427 19:22:02.045 [SimpleThreadPoolWorker-2] DEBUG o.s.b.c.r.d.JdbcStepExecutionDao # Truncating long message before update of StepExecution, original message is: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [
UPDATE JOB_RUN
SET SYS_RUN_STUS_CD = ?,
UPDT_USER_ID = 'SYSTEM',
REC_UPDT_TS = CURRENT_TIMESTAMP
WHERE JOB_RUN_ID = ?
]; SQL state [null]; error code [0]; enlist: caught Exception; nested exception is java.sql.SQLException: enlist: caught Exception
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:909)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:933)
at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:313)
at com.abc.common.dao.jdbc.JobRunJdbcDao.updateJobStatus(JobRunJdbcDao.java:199)
at com.abc.common.dao.jdbc.JobRunJdbcDao.updateJobStatus(JobRunJdbcDao.java:193)
at com.abc.bpe.core.InitializingTasklet.execute(InitializingTasklet.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport$1.doInTransaction(TransactionAspectSupport.java:304)
at org.springframework.transaction.jta.WebSphereUowTransactionManager$UOWActionAdapter.run(WebSphereUowTransactionManager.java:347)
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderCurrentUOW(EmbeddableUOWManagerImpl.java:954)
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderUOW(EmbeddableUOWManagerImpl.java:370)
at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:290)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:298)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy118.execute(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy106.execute(Unknown Source)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
at org.springframework.transaction.jta.WebSphereUowTransactionManager$UOWActionAdapter.run(WebSphereUowTransactionManager.java:347)
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderNewUOW(EmbeddableUOWManagerImpl.java:775)
at com.ibm.ws.uow.embeddable.EmbeddableUOWManagerImpl.runUnderUOW(EmbeddableUOWManagerImpl.java:368)
at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:290)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:198)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:165)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:304)
at com.abc.bpe.core.support.CompositeJobLauncher.runJob(CompositeJobLauncher.java:207)
at com.abc.des.bpe.core.support.CompositeJobLauncher$1.run(CompositeJobLauncher.java:119)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)
Caused by: java.sql.SQLException: enlist: caught Exception
at com.ibm.ws.rsadapter.AdapterUtil.toSQLException(AdapterUtil.java:1000)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.beginTransactionIfNecessary(WSJdbcConnection.java:513)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2373)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2339)
at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:238)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:638)
... 60 more
Caused by: javax.resource.ResourceException: enlist: caught Exception
at com.ibm.ejs.j2c.LocalTransactionWrapper.enlist(LocalTransactionWrapper.java:585)
at com.ibm.ejs.j2c.ConnectionManager.lazyEnlist(ConnectionManager.java:1726)
at com.ibm.ws.rsadapter.spi.WSRdbManagedConnectionImpl.lazyEnlist(WSRdbManagedConnectionImpl.java:2084)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.beginTransactionIfNecessary(WSJdbcConnection.java:468)
... 64 more
Caused by: java.lang.IllegalStateException: Illegal attempt to enlist multiple 1PC XAResources
at com.ibm.tx.jta.impl.RegisteredResources.enlistResource(RegisteredResources.java:441)
at com.ibm.tx.jta.impl.TransactionImpl.enlistResource(TransactionImpl.java:2252)
at com.ibm.tx.jta.embeddable.impl.EmbeddableTranManagerSet.enlistOnePhase(EmbeddableTranManagerSet.java:202)
at com.ibm.ws.transaction.services.TransactionManagerService.enlistOnePhase(TransactionManagerService.java:382)
at com.ibm.ejs.j2c.LocalTransactionWrapper.enlist(LocalTransactionWrapper.java:501)
... 67 more
I added #Transactional to the InitializingTasklet.execute(...) method
Any help regarding this issue is greatly appreciated. Also if any other code needed, please let know
Thanks
EDIT 3:
serviceBeans.xml
<tx:advice id="txServiceAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="runJob" propagation="REQUIRED" rollback-for="Throwable" isolation="READ_COMMITTED" />
</tx:attributes>
</tx:advice>
<!-- commented the below line now and change the transactionManager-->
<!-- <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> -->
<bean id="txManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />
<tx:annotation-driven transaction-manager="txManager" />
EDIT 2:
I removed multiple transaction managers and now only have the WebspereUOWTransactionManager
EDIT
Additional code:
BatchServiceImpl (Added #Transactional):
#Override
#Transactional(value = "transactionManager", rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public void launchJob(JobLaunchRequest request) throws ServiceException {
try {
logger.info("Launching job: " + request.getJobParameters().toString());
jobLauncher.runAll(request.getJobParameters());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Code that calls the DAO:
public class ParameterBasedCompositeJobLauncher implements CompositeJobLauncher, InitializingBean {
public Collection<JobExecution> runAll(final Collection<JobExecutionParameters> jobParameterSet)
throws JobExecutionAlreadyRunningException, JobRestartException,
JobInstanceAlreadyCompleteException, JobParametersInvalidException {
....
jobRunDao.updateJobStatus(batchId, jobRunStatus);
....
}
}
ApplicationContext.xml
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRES_NEW" rollback-for="Exception" isolation="READ_COMMITTED" />
<tx:method name="update*" propagation="REQUIRES_NEW" rollback-for="Exception" isolation="READ_COMMITTED" />
</tx:attributes>
</tx:advice>
spring-dataSource.xml
<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate"
c:dataSource-ref="dataSource" />
spring-launch-context.xml
<bean id="jobLauncher" class="com.abc.core.support.ParameterBasedCompositeJobLauncher">
<property name="jobRepository" ref="jobRepository" />
<property name="taskExecutor" ref="taskExecutor"/>
<property name="jobLocator" ref="jobRegistry" />
<property name="jobRunDao" ref="jobRunDao"/>
<property name="forwardJobClient" ref="integration-forwardJobClient"/>
<property name="responseFileGenerator" ref="responseFileGenerator"/>
</bean>
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
<bean id="jobRepository"
p:dataSource-ref="dataSource"
p:transactionManager-ref="transactionManager"
p:lobHandler-ref="lobHandler"
p:tablePrefix="${SCHEMA}.BATCH_"
p:isolationLevelForCreate="ISOLATION_READ_COMMITTED"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"/>

Maven build error on Junit test case for service layer

I am trying to write a simple Junit test case to test service/dao layer of my project. But I get compilation error when I build it using Maven. Kindly help me with this.
Code:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = {"/C:/project/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml"})
public class AServiceTest {
#Autowired
private AService aService;
#Test
public void testValidate() throws Exception {
String user = "user10";
String pass = "pass10";
String flag = "failure";
User response = aService.validate(user, pass);
if (user.equalsIgnoreCase(response.getUser()) && pass.equals(response.getPass())) {
flag="success";
assertEquals("success", flag);
}
}
}
Error:
package org.springframework.test.context does not exist
Update:
The dependency for spring-test was missing my pom.xml, I added the same and the above error is gone but I get a new error now.
Error:
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener#3b5587] to prepare
test instance [com.sample.project.controller.AServiceTest#16c1857]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [C:/project/src/main/webapp/WEB-
INF/mvc-dispatcher-servlet.xml]; nested exception is java.io.FileNotFoundException: class path resource [C:/project/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:81)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:280)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:304)
... 30 more
Caused by: java.io.FileNotFoundException: class path resource [C:/project/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 39 more
Context file:
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="com.sample.project" />
<mvc:annotation-driven />
<jee:jndi-lookup id="sampleDS" jndi-name="java:/comp/env/jdbc/sampleDS" expected-type="javax.sql.DataSource"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="sampleDS"/>
</bean>
<bean id="myTxManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="myTxManager" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
Without having access to your configuration and how things are set up on your environment, it is really hard to help.
From the exception, it would seem that you have not correctly configured the application context files for the spring framework. The error message is quite explicit:
Caused by: java.io.FileNotFoundException: class path resource [C:/project/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml] cannot be opened because it does not exist
I am not sure what your experience with spring is but I would read up on that. Useful links below:
Step by step spring MVC
Setting up MVC environment
For the tests:
Spring source documentation
Blog about MVC testing

org.springframework.core.NestedIOException: Cannot find Velocity template for URL

Velocity Configuration with spring,I am missing some configuration. Please tell me why it is happening so.
Getting the below error when I hit my url.
SEVERE: Servlet.service() for servlet springDispatcher threw exception
org.springframework.core.NestedIOException: Cannot find Velocity template for URL [layout.vm]: Did you specify the correct resource loader path?; nested exception is org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'layout.vm'
at org.springframework.web.servlet.view.velocity.VelocityLayoutView.checkResource(VelocityLayoutView.java:133)
at org.springframework.web.servlet.view.UrlBasedViewResolver.loadView(UrlBasedViewResolver.java:438)
at org.springframework.web.servlet.view.AbstractCachingViewResolver.createView(AbstractCachingViewResolver.java:186)
at org.springframework.web.servlet.view.UrlBasedViewResolver.createView(UrlBasedViewResolver.java:401)
at org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName(AbstractCachingViewResolver.java:103)
at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1211)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1160)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
spring-context.xml
<bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/velocity/" />
</bean>
<!-- View resolvers can also be configured with ResourceBundles or XML files.
If you need different view resolving based on Locale, you have to use the
resource bundle resolver. -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".vm" />
</bean>
I'm getting the below exception when the velocityconfig is dropped.
org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.springframework.web.servlet.view.velocity.VelocityConfig] is defined: expected single bean but found 0
at org.springframework.beans.factory.BeanFactoryUtils.beanOfTypeIncludingAncestors(BeanFactoryUtils.java:367)
at org.springframework.web.servlet.view.velocity.VelocityView.autodetectVelocityEngine(VelocityView.java:239)
at org.springframework.web.servlet.view.velocity.VelocityView.initApplicationContext(VelocityView.java:225)
at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
at org.springframework.beans.fact
If I am not wrong, you will be able to achieve the Velocity configuration using your viewResolver alone.
Modify your prefix to the one mentioned in your resourceLoaderPath and it should be fine (didn't test it myself)
<property name="prefix"><value>/WEB-INF/velocity/</value></property>
Also, you could drop the velocityConfig tag altogether.
you should use
(bean id="ViewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver")
not
(bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver")
this bean use 'layout.vm',i also have this problem.

SPRING DATA-JPA + eclipseLink2.0 failed

In my test project, Spring container can't create a bean that extends JpaRepository due to following error.
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'srSvcInfoMtrRepository': FactoryBean
threw exception on object creation; nested exception is
java.lang.NoSuchMethodError:
javax.persistence.EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
It might be the problem relevant to JPA version.
I specified certain persistenceProvider in eclipelink2.0(org.eclipse.persistence.jpa.PersistenceProvider) at persistence.xml.
do you have any idea about this problem?
Stacktrace
2012-05-14 09:11:08 ERROR Caught
exception while allowing TestExecutionListener
[org.springframework.test.context.support.DependencyInjectionTestExecutionListener#112da40]
to prepare test instance
*> [net.tjjang.learn.spring_jpa.test.SrSvcInfoMtrTest#b6d6ab]
java.lang.IllegalStateException: Failed to load ApplicationContext at
org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
at
org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at
org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at
org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'srSvcInfoMtrRepository': FactoryBean
threw exception on object creation; nested exception is
java.lang.NoSuchMethodError:
javax.persistence.EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;
at
org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
at
org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1441)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:305)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at
org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
at
org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
at
org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
at
org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
at
org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
... 24 more
> Caused by: java.lang.NoSuchMethodError:
javax.persistence.EntityManager.getMetamodel()Ljavax/persistence/metamodel/Metamodel;*
at
org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getMetadata(JpaEntityInformationSupport.java:56)
at
org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:145)
at
org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:83)
at
org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:66)
at
org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:146)
at
org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:120)
at
org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:39)
at
org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
JpaRepository Class()
package net.tjjang.learn.spring_jpa.repositories;
import net.tjjang.learn.spring_jpa.domain.SrSvcInfoMtr;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;
#Transactional(readOnly = true)
public interface SrSvcInfoMtrRepository extends JpaRepository<SrSvcInfoMtr, String> {
Page<SrSvcInfoMtr> findBySvc_nm(String svc_nm, Pageable pageable);
}
app-context.xml(not all the contents of app-context.xml)
<!-- for data access -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="cubrid.jdbc.driver.CUBRIDDriver" p:url="jdbc:cubrid:localhost:30000:test:test::"
p:username="test" p:password="*******" p:initialSize="5" p:maxActive="10">
</bean -->
<bean
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property name="dataSource" ref="dataSource" />
<property name="loadTimeWeaver">
<bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
<property name="persistenceUnitName" value="JpaPersistenceUnit" />
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<jpa:repositories base-package="net.tjjang.learn.spring_jpa" />
<import resource="infrastructure.xml" />
Persistence.xml
<persistence-unit name="JpaPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>net.tjjang.learn.spring_jpa.domain.Car</class>
<class>net.tjjang.learn.spring_jpa.domain.SrSvcInfoMtr</class>
<properties>
<property name="eclipselink.logging.level" value="INFO" />
</properties>
</persistence-unit>
Libraries
\org\springframework\spring-aop\3.1.0.RELEASE\spring-aop-3.1.0.RELEASE.jar
\aopalliance\aopalliance\1.0\aopalliance-1.0.jar
\org\springframework\spring-asm\3.1.0.RELEASE\spring-asm-3.1.0.RELEASE.jar
\org\springframework\spring-core\3.1.0.RELEASE\spring-core-3.1.0.RELEASE.jar
\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar
\org\springframework\spring-orm\3.1.0.RELEASE\spring-orm-3.1.0.RELEASE.jar
\org\springframework\spring-jdbc\3.1.0.RELEASE\spring-jdbc-3.1.0.RELEASE.jar
\org\springframework\spring-tx\3.1.0.RELEASE\spring-tx-3.1.0.RELEASE.jar
\org\springframework\spring-aspects\3.1.0.RELEASE\spring-aspects-3.1.0.RELEASE.jar
\org\springframework\spring-context\3.1.0.RELEASE\spring-context-3.1.0.RELEASE.jar
\org\springframework\spring-expression\3.1.0.RELEASE\spring-expression-3.1.0.RELEASE.jar
\org\springframework\spring-context-support\3.1.0.RELEASE\spring-context-support-3.1.0.RELEASE.jar
\org\springframework\spring-beans\3.1.0.RELEASE\spring-beans-3.1.0.RELEASE.jar
\org\springframework\spring-test\3.1.0.RELEASE\spring-test-3.1.0.RELEASE.jar
\org\springframework\spring-instrument\3.1.0.RELEASE\spring-instrument-3.1.0.RELEASE.jar
\junit\junit\4.8.2\junit-4.8.2.jar
\org\slf4j\slf4j-api\1.6.0\slf4j-api-1.6.0.jar
\org\slf4j\jcl-over-slf4j\1.6.0\jcl-over-slf4j-1.6.0.jar
\org\slf4j\slf4j-log4j12\1.6.0\slf4j-log4j12-1.6.0.jar
\log4j\log4j\1.2.16\log4j-1.2.16.jar
\cubrid\cubrid-jdbc\8.4.1.2032\cubrid-jdbc-8.4.1.2032.jar
\org\eclipse\persistence\eclipselink\2.0.0\eclipselink-2.0.0.jar
\org\springframework\data\spring-data-jpa\1.0.3.RELEASE\spring-data-jpa-1.0.3.RELEASE.jar
\org\springframework\data\spring-data-commons-core\1.1.0.RELEASE\spring-data-commons-core-1.1.0.RELEASE.jar
\org\hibernate\ejb3-persistence\1.0.2.GA\ejb3-persistence-1.0.2.GA.jar
\org\aspectj\aspectjrt\1.6.8\aspectjrt-1.6.8.jar
\org\aspectj\aspectjweaver\1.6.11\aspectjweaver-1.6.11.jar
\commons-dbcp\commons-dbcp\1.2.2-p1\commons-dbcp-1.2.2-p1.jar
\commons-pool\commons-pool\1.4\commons-pool-1.4.jar
\mysql\mysql-connector-java\5.1.10\mysql-connector-java-5.1.10.jar
Spring Data JPA requires JPA 2.0. You have pulled the 1.0 version of it into your classpath (the ejb3-persistence-1.0.2.GA.jar, by whatever means). Make sure you use a recent version of EclipseLink that supports JPA 2.0. Version 2.3.2 is the current release version.

Resources