title: Unable to retrieve data from my database with spring
body: <p>I'm trying to save a list of objects that have others objects as attributes using <strong><em>save()</em></strong> method of <strong><em>Spring   CrudRepository</em></strong>.
  My service is as below</p>
  
  <pre><code>@Service
  @Transactional
  public class DBDataManipulatorServiceImpl implements DBDataManipulatorService {
  
  @Autowired
  private AircraftRepository aircraftRepository;
  @Autowired
  private WorkPackageRepository workPackageRepository;
  @Autowired
  private MyJobRepository myJobRepository;
  
  @Override
  @Transactional
  public List&lt;MyJob&gt; saveToDataBase(List&lt;MyJob&gt; jobs) {
  
      List&lt;MyJob&gt; newJobs = new ArrayList&lt;MyJob&gt;();
      MyJob myJob = null;
  
      for (MyJob job : jobs) {
          myJob = myJobRepository.save(job);
          newJobs.add(myJob);
      }
  
      return newJobs;
  } ...
  </code></pre>
  
  <p>and myJob class is:</p>
  
  <pre><code>@Entity
  @Table(name="job", uniqueConstraints=@UniqueConstraint(columnNames={"jobId"}))
  public class MyJob implements Serializable {
  
  
  @Id
  @Column(name = "jobId")
  private String jobId;
      private String jobStatus;
  
      @ManyToOne()
  private Aircraft aircraft;
  
  @ManyToOne()
  private WorkPackage workPackage;
  ....
  </code></pre>
  
  <p>And Aircraft class is:</p>
  
  <pre><code>@Entity
  @Table(name="aircraft", uniqueConstraints=@UniqueConstraint(columnNames={"aircraftId"}))
  public class Aircraft implements Serializable{
  
  
  @Id
  @Column(name = "aircraftId")
  private String aircraftId;
  
  @Column (name = "TYPE")
  private String type;
  
  @Column (name = "MODEL")
  private String model;
  </code></pre>
  
  <p>And when I execute the following test : </p>
  
  <pre><code>@Test
  public void testSaveToDataBaseWithFiles() {
  
  HTMLDataExtractorServiceImpl htmlDataExtractorService = new    HTMLDataExtractorServiceImpl();
      Map&lt;String, MyJob&gt; jobsMap = htmlDataExtractorService.parsePage("/Report.html");
      List&lt;MyJob&gt; jobs = new ArrayList&lt;MyJob&gt;(jobsMap.values());
  
      List&lt;MyJob&gt; myjobs =  dbDataManipulatorService.saveToDataBase(jobs);
  
      jobsMap = myJobsListToMyJobsMap(myjobs);
  
      MyJob myJob = jobsMap.get("20316408");
  
      assertEquals("SUCCESS",myJob.getJobStatus());
      assertEquals("50005", myJob.getAircraft().getAircraftId());
      assertEquals("WP6_27", myJob.getWorkPackage().getWorkPackageId());
  
  }
  </code></pre>
  
  <p>I get the following error: </p>
  
  <pre><code>org.springframework.orm.jpa.JpaObjectRetrievalFailureException: Unable to find com.domain.Aircraft with id 50004; nested exception is javax.persistence.EntityNotFoundException: Unable to find com.domain.Aircraft with id 50004
  </code></pre>
  
  <p>I understand that there is a problem with the save method, but I don't know how to solve it.  Can anyone help, please?</p>