I am newbie to Spring-Data-Rest. I am doing a simple rest application where i will make a rest call to get data from database in JSON. But while testing the REST in POSTMAN i am getting below error.
<html>
<head>
<title>Apache Tomcat/7.0.57 - Error report</title>
<style>
<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}-->
</style>
</head>
<body>
<h1>HTTP Status 500 - Could not write JSON: Detected multiple association links with same relation type! Disambiguate association @javax.persistence.OneToMany(fetch=LAZY, mappedBy=sport, orphanRemoval=false, targetEntity=class co.vitti.sports.bean.CustomerPackage, cascade=[]) private java.util.List co.vitti.sports.bean.Sport.listOfCustomerPackage using @RestResource! (through reference chain: org.springframework.hateoas.Resources["_embedded"]->java.util.UnmodifiableMap["bookings"]->java.util.ArrayList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Detected multiple association links with same relation type! Disambiguate association @javax.persistence.OneToMany(fetch=LAZY, mappedBy=sport, orphanRemoval=false, targetEntity=class co.vitti.sports.bean.CustomerPackage, cascade=[]) private java.util.List co.vitti.sports.bean.Sport.listOfCustomerPackage using @RestResource! (through reference chain: org.springframework.hateoas.Resources["_embedded"]->java.util.UnmodifiableMap["bookings"]->java.util.ArrayList[0])</h1>
<HR size="1" noshade="noshade">
<p>
<b>type</b> Exception report
</p>
<p>
<b>message</b>
<u>Could not write JSON: Detected multiple association links with same relation type! Disambiguate association @javax.persistence.OneToMany(fetch=LAZY, mappedBy=sport, orphanRemoval=false, targetEntity=class co.vitti.sports.bean.CustomerPackage, cascade=[]) private java.util.List co.vitti.sports.bean.Sport.listOfCustomerPackage using @RestResource! (through reference chain: org.springframework.hateoas.Resources["_embedded"]->java.util.UnmodifiableMap["bookings"]->java.util.ArrayList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Detected multiple association links with same relation type! Disambiguate association @javax.persistence.OneToMany(fetch=LAZY, mappedBy=sport, orphanRemoval=false, targetEntity=class co.vitti.sports.bean.CustomerPackage, cascade=[]) private java.util.List co.vitti.sports.bean.Sport.listOfCustomerPackage using @RestResource! (through reference chain: org.springframework.hateoas.Resources["_embedded"]->java.util.UnmodifiableMap["bookings"]->java.util.ArrayList[0])</u>
</p>
<p>
My Booking.java class
@Entity
@Table(name="booking", catalog="db_sports" )
public class Booking implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id", nullable=false)
private Integer id ;
private Date bookingDate ;
private Integer trainerFlag ;
private Date createdAt ;
private Date updatedAt ;
@ManyToOne
@JoinColumn(name="timeslot_id", referencedColumnName="id")
private Timeslot timeslot ;
//setters and getters
My Timeslot.java
@Entity
@Table(name="timeslot", catalog="db_sports" )
public class Timeslot implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="id", nullable=false)
private Integer id ;
@Column(name="slot_start_time", nullable=false)
private Date slotStartTime ;
@Column(name="slot_end_time", nullable=false)
private Date slotEndTime ;
@OneToMany(mappedBy="timeslot", targetEntity=Booking.class)
private List<Booking> listOfBooking;
//setters and getters
in Booking.java
I deleted my TimeSlotRepository.java to get JSON instead of links in POSTMAN. But i am getting the above error.
Can anyone please help me. to get Timeslot JSON when i make a REST call to Booking.
Aucun commentaire:
Enregistrer un commentaire