已经有了PO的POJO

时间:2017-07-12 12:29:39

标签: spring hibernate jpa spring-boot jackson

我有两个类Job和Client。客户可以有很多工作。这两个课程如下: -

@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;

我在数据库中有一个id = 1的客户端,我希望将客户端的id保存为作业表中的外键.json的一部分如下: -

{
    "client":{"clientId":1}
}

我得到的错误是: -

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]]

有人可以帮我解决这个问题吗?

0 个答案:

没有答案