简体   繁体   中英

Jpa Parent-Child Relationship doesnt work on mysql

I have a category table that has a relationship parent-child, When I insert data on MySQL relationship doesn't work I see empty children, but when I send the same request from the postman it worked. I'm trying to understand what the behind is? Can someone explain me, please?

@JsonManagedReference(value = "parent_category")
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
private Set<CatalogCategory> children = new HashSet<>();

@ManyToOne
@JoinColumn(name = "parentId")
@JsonBackReference(value = "parent_category")
private CatalogCategory parent;

With your postman, you use these JPA annotations because you run the code of your Java application.

JPA will generate some SQL request to insert this data. You can show this request in the logs with some configuration: https://www.baeldung.com/sql-logging-spring-boot

I think that your SQL requests, you insert in your MySQL database, are different.

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