简体   繁体   中英

Spring boot jpa the FK pointing at the wrong PK

Hi when I adding two list to my ListA tabell where I use Rest Api ListA, the first list have id 1 and the other list have id 2

After I execute rest api for ListB just one time and also adding data from id 2 from ListA. I get status 200 in postman with right details.

When I looking at my database I see that the FK is pointing at wrong PK from tabell ListA instead pointing at PK id 2 its pointing PK id 1 in tabell ListA.

Summary

My FK in ListB is not pointing at the right PK in tabell ListA

@MapsId
@JoinColumn(name = "listA_fk")
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private ListA listA;


@OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="listA")
@JsonIgnore
private ListB ListB;

这就是@MapsId,共享ID,删除@MapsId。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM