diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java
index 4686388ff..3fc4e90ac 100644
--- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java
+++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java
@@ -190,6 +190,7 @@ public class SimpleJobRepository implements JobRepository {
}
jobInstance.setLastExecution(lastExecution);
jobInstance.setStepNames(getStepNames(job));
+ jobInstance.setJob(job);
}
else if (jobs.size() == 0) {
// no job found, create one
diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryIntegrationTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryIntegrationTests.java
new file mode 100644
index 000000000..7d748b638
--- /dev/null
+++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryIntegrationTests.java
@@ -0,0 +1,70 @@
+package org.springframework.batch.execution.repository;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.batch.core.domain.Job;
+import org.springframework.batch.core.domain.JobExecution;
+import org.springframework.batch.core.domain.JobParameters;
+import org.springframework.batch.core.domain.JobSupport;
+import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
+import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
+import org.springframework.util.ClassUtils;
+
+/**
+ * Repository tests using JDBC DAOs (rather than mocks).
+ *
+ * @author Robert Kasanicky
+ */
+public class SimpleJobRepositoryIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
+
+ protected String[] getConfigLocations() {
+ return new String[] { ClassUtils.addResourcePathToPackagePath(getClass(), "dao/sql-dao-test.xml") };
+ }
+
+ private SimpleJobRepository jobRepository;
+
+ public void setJobRepository(SimpleJobRepository jobRepository) {
+ this.jobRepository = jobRepository;
+ }
+
+ /**
+ * Create two job executions for same job+parameters tuple. Check both
+ * executions belong to the same job instance and job.
+ */
+ public void testCreateAndFind() throws Exception {
+
+ JobSupport job = new JobSupport("testJob");
+ job.setRestartable(true);
+
+ Map stringParams = new HashMap() {
+ {
+ put("stringKey", "stringValue");
+ }
+ };
+ Map longParams = new HashMap() {
+ {
+ put("longKey", new Long(1));
+ }
+ };
+ Map dateParams = new HashMap() {
+ {
+ put("dateKey", new Date(1));
+ }
+ };
+ JobParameters jobParams = new JobParameters(stringParams, longParams, dateParams);
+
+ JobExecution firstExecution = jobRepository.createJobExecution(job, jobParams);
+
+ assertEquals(job, firstExecution.getJobInstance().getJob());
+
+ jobRepository.saveOrUpdate(firstExecution);
+ firstExecution.stop();
+ jobRepository.saveOrUpdate(firstExecution);
+ JobExecution secondExecution = jobRepository.createJobExecution(job, jobParams);
+
+ assertEquals(firstExecution.getJobInstance(), secondExecution.getJobInstance());
+ assertEquals(job, secondExecution.getJobInstance().getJob());
+ }
+}
\ No newline at end of file
diff --git a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml
index 34d7ca997..b2ee99cf2 100644
--- a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml
+++ b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml
@@ -4,6 +4,12 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+
+
+
+
+