API Rest - Many to One

0

I am trying to create a one to many relationship, my problem is that when I make a request with the entity that has the ManyToOne this does not return anything is limited to giving me an error of Expected ':' instead of 'a' .

The entities are the following.

@Entity
@Table(name = "teams", uniqueConstraints = {@UniqueConstraint(columnNames = {"id"})})
public class Team implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    //Otras propiedades...

    @ManyToOne
    private Country country;
}

And on the part of @OneToMany is the following:

@Entity
@Table(name = "country")
public class Country implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    //Otras propiedades...

    @OneToMany(cascade=CascadeType.ALL, mappedBy="country")
    private List<Team> teams;
}

The repository:

@Repository
public interface TeamRepository extends JpaRepository<Team, Long> {

}

And the controller:

@GetMapping(value = "/{id}")
public Team getPersona(@PathVariable("id") int id) {
    return teamRepository.findOne(genericMethods.toLong(id));
}

Well, when I want to obtain the country of the team, I get the error that I mentioned earlier, does anyone know why?

I had thought about putting the property @JsonIgnore in the entity Team to the ManyToOne and adding an attribute making it One To One.

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "book_detail_id")
private Country countryReturn;
    
asked by jc1992 16.09.2018 в 17:43
source

1 answer

1

You have failed to specify the join column in your manyToOne property:

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "book_detail_id")
private Country countryReturn;
    
answered by 07.11.2018 / 08:12
source