I am using spring boot rest api, data jpa, I just want to use event class and not to update from person class. Following are entity classes,
@Entity
@Table(name = "person")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer person_id;
private Integer age;
String first_name;
String last_name;
@ManyToMany(fetch = FetchType.LAZY,
cascade = {
CascadeType.PERSIST,
CascadeType.MERGE
})
@JoinTable(name = "person_event",
joinColumns = { @JoinColumn(name = "person_id") },
inverseJoinColumns = { @JoinColumn(name = "event_id") })
private Set<Event> event;
}
Event class is
@Entity
@Table(name = "event")
public class Event {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer event_id;
private String event_date;
private String title;
}
I am adding the values from postman as json string, I want to add the event values from event entity, But I dont want to update those values from person entity. From person entity I just want to use the event id but I dont want to update the event table.
{
"age": 32,
"first_name": "Srinath",
"last_name": "murugula",
"event": [
{
"event_id": 1
},
{
"event_id": 3
}
]
}
The above string is to adding the person but also updating the other fields of entity class(ie, event_date and title as null.Because I am not mentioning those fields.In Person class I just want use id but dont want to update event table fields.
You can use:
@Cascade({CascadeType.SAVE_UPDATE})
https://mkyong.com/hibernate/cascade-jpa-hibernate-annotation-common-mistake/
I have used:
@Cascade({CascadeType.Detach})
It solved my problem. Working fine.
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.