I have two classes Job and Client. A client can have many jobs.The two classes are as follows:-
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class,property="jobId", scope = Job.class)
public class Job {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "job_id")
private long jobId;
@ManyToOne
private Client client;
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
@Entity
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "clientId",scope = Client.class)
public class Client {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long clientId;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "client")
@Transient
private Collection<Job> jobs;
I have a client with id=1 in database and I want to save the id of the client as a foreign key in job table .A part of json is as follows:-
{
"client":{"clientId":1}
}
The error I get is :-
Could not read JSON document: Already had POJO for id (java.lang.Long) [[ObjectId: key=1, type=com.fasterxml.jackson.databind.deser.impl.PropertyBasedObjectIdGenerator, scope=java.lang.Object]]
Could someone please help me on this?