How to write model class and establish relation between classes. To save and update the below the JSON using spring boot.
inputJSON
{
"modelName": "",
"modelDescription": "",
"recordStatus": true,
"details": [
{
"tMemberDetail": {
"param1": "",
"pn": {
"param1": "",
"param2": ""
},
"an": {
"param1": "",
"param2": ""
},
"p": {
"h": {
"param1": "",
"param2": ""
},
"v": {
"param1": "",
"param2": ""
},
"r": {
"param1": "",
"param2": ""
}
},
"t": {
"param1": ""
}
},
"mattributes": {
"param1": "",
"SP": {
"param1": "",
"param2": ""
},
"EP": {
"param1": "",
"param2": ""
},
"F": {
"Required": false,
"FT": "",
"G": {
"param1": ""
},
"FP": {
"param1": "",
"param2": ""
},
"Pmr": {
"Required": false,
"Details": {
"param1": "",
"param2": ""
}
},
"Pnt": {
"Required": false,
"Details": {
"param1": "",
"param2": ""
}
},
"ASS": {
"Required": false,
"Details": {
"param1": ""
}
},
"NPA": {
"Required": false,
"Details": {
"param1": "",
"param2": ""
}
}
},
"Start": {
"param1": "",
"Loads": {
"param1": ""
}
},
"End": {
"param1": "",
"Loads": {
"param1": ""
}
}
}
}
]
}
I have tried to achieve by writing model class like below
@Setter
@Getter
@ToString
@Entity
@NoArgsConstructor
public class Model extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long modelId;
private String modelName;
private String modelDescription;
private RecordStatus recordStatus=RecordStatus.ACTIVE;
}
@Setter
@Getter
@Entity
@NoArgsConstructor
public class TModel extends Model implements Serializable{
private static final long serialVersionUID = 7331603514610649855L;
@OneToMany(cascade = CascadeType.ALL , orphanRemoval = true)
private List<TMember > tMembers ;
}
@Setter
@Getter
@ToString
@Entity
@NoArgsConstructor
public class TMember implements Serializable{
private static final long serialVersionUID = 7331603514610649855L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long tMemberId;
@OneToOne(cascade = CascadeType.ALL , orphanRemoval = true)
private TMemberDetail tMemberDetail;
@OneToOne(cascade = CascadeType.ALL , orphanRemoval = true)
private MemberAttribute memberAttributes;
}
The problem I am facing here is that every time I update call child objects, auto incremental id's are incremented by 1.
If I call get service from another application I get only
modelName, modelDescription, recordStatus but not the entire data.