Hello i am using spring with JPA and mysql i have a class FishJournal
@Entity
@Table(name = "journal")
public class FishJournal {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(targetEntity =User.class,cascade = CascadeType.ALL)
@JoinColumn(name="user_id", referencedColumnName = "id")
private User users;
@ManyToOne(targetEntity =Fish.class,cascade = CascadeType.ALL)
@JoinColumn(name="fish_id", referencedColumnName = "id")
private Fish fishes;
@ManyToOne(targetEntity =Water.class,cascade = CascadeType.ALL)
@JoinColumn(name="water_id", referencedColumnName = "id")
private Water waters;
@ManyToOne(targetEntity =Bait.class,cascade = CascadeType.ALL)
@JoinColumn(name="bait_id", referencedColumnName = "id")
private Bait baits;
Date date;
String info;
String path;
boolean shared;
getters and setter() {
}
And I want it to have a unidirectional many-to-one relationship with user,water,bait and fish. I want to be able when given the FishJournal object to be able to get the data for those fields. The problem is when I try to use JPA to query a fishjournal from the database with jpa an infinity recursion occurs and the only way I was able to fix it was to change the getWaters,getUsers methods to return only the name and not the whole object.That isn't good enough because I want to be able to use the whole objects as getters.