модель классов
@Entity
@Table(name="RequisitionRequest")
public class Requisition {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String requestedPerson;
private String contactDetails;
private String appliedDate;
private String branch;
private String department;
private String status;
@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER,mappedBy = "RequisitionRequest")
private List<Nationality> nationality;
//getters and setters
}
класс Национальность
@Entity
@Table(name="nationality")
public class Nationality {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String nationality;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "nationality_id", nullable = false)
private Requisition requisition;
//getters and setters
}
классы хранилища
@Repository
public interface NationalityRepository extends JpaRepository<Nationality,Long>{
}
@Repository
public interface RequisitionRepository extends JpaRepository<Requisition,Long> {
}
класс обслуживания
@Service
public class RequisitionServiceImpl implements RequisitionService {
@Autowired
RequisitionRepository requisitionRepository;
@Override
public void save(Requisition requisition) {
requisitionRepository.save(requisition);
}
}
класс контроллера
@RestController
public class RequisitionController {
@Autowired
RequisitionService requisitionService;
@Autowired
RequisitionRepository requisitionRepository;
@PostMapping("/requisition/")
@CacheEvict(value = "requisitions", allEntries=true)
public ResponseEntity<Requisition> addRequisition(@RequestBody Requisition requisition) {
System.out.print(requisition);
Requisition requisitionR = new Requisition();
Requisition response = new Requisition();
requisitionR.setBranch(requisition.getBranch());
requisitionR.setDepartment(requisition.getDepartment());
requisitionR.setExpectedDateofJoin(requisition.getExpectedDateofJoin());
//requisitionR.setNationality(requisition.getNationality());
requisitionRepository.save(requisitionR);
return new ResponseEntity<Requisition>(response, HttpStatus.OK);
}
Я учусь весенней загрузке, просто пишу пример программы для изучения весенней загрузки + jpa + отношение один-ко-многим. При выполнении приведенного выше кода получаю ошибку, такую как
Причина: orgИсключение-core-5.0.12.Final.jar: 5.0.12.Final] в org.hibernate.cfg.annotations.CollectionBinder $ 1.secondPass (CollectionBinder.java:719) ~ [hibernate-core-5.0.12.Final.jar: 5.0.12.Final] в org.hibernate.cfg.CollectionSecondPass.doSecondPass (CollectionSecondPass.java:54) ~ [hibernate-core-5.0.12.Final.jar: 5.0.12.Final] в org.hibernate.boot.яnternal.InFlightMetadataCollectorImpl.processSecondPasses (InFlightMetadataCollectorImpl.java:1655) ~ [hibernate-core-5.0.12.Final.jar: 5.0.12.Final] в org.hibernate.boot.internal.InFlightMetampl.Impl.) ~ [hibernate-core-5.0.12.Final.jar: 5.0.12.Final] на org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete (MetadataBuildingProcess.java:278) ~ [hibernate-core-5.0.12.Final.jar: 5.0.12.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata (EntityManagerFactoryBuilderImpl.java:847) ~ [hibernate-entitymanager-5.0.12.Final.jar 5.0:.12.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build (EntityManagerFactoryBuilderImpl.java:874) ~ [hibernate-entitymanager-5.0.12.Final.jar: 5.0.12.Final]
Я попробовал решения, уже упомянутые на этом сайте, но у меня это не работает.Может кто-нибудь помочь мне решить эту проблему