Inheritance in Json Response Spring boot - json

I have two classes, A and B:
class A{
private int numberOne;
private int numberTwo;
public int getNumberOne() {
return numberOne;
}
public void setNumberOne(int numberOne) {
this.numberOne = numberOne;
}
public int getNumberTwo() {
return numberTwo;
}
public void setNumberTwo(int numberTwo) {
this.numberTwo = numberTwo;
}
}
class B extends A {
private int numberThree;
public int getNumberThree() {
return numberThree;
}
public void setNumberThree(int numberThree) {
this.numberThree = numberThree;
}
}
How do I can like this:
ResponseEntity<A> someMethod(){
return new B(1,2,3);
}
json
{
"numberOne":"1",
"numberTwo":"2"
}
ResponseEntity<B> someMethod(){
return new B(1,2,3);
}
json
{
"numberOne":"1",
"numberTwo":"2",
"numberThree":"3"
}
How can I use JSON ignoring in Spring Boot which I want?

You create new class
public class Views {
public static class Public {
}
public static class Internal extends Public {
}
}
A.class
public class A {
public A(int numberOne, int numberTwo) {
this.numberOne = numberOne;
this.numberTwo = numberTwo;
}
#JsonView(Views.Public.class)
private int numberOne;
#JsonView(Views.Public.class)
private int numberTwo;
public int getNumberOne() {
return numberOne;
}
public void setNumberOne(int numberOne) {
this.numberOne = numberOne;
}
public int getNumberTwo() {
return numberTwo;
}
public void setNumberTwo(int numberTwo) {
this.numberTwo = numberTwo;
}
}
B.class
public class B extends A{
#JsonView(Views.Internal.class)
private int numberThree;
public B(int numberOne, int numberTwo) {
super(numberOne, numberTwo);
}
public B(int numberOne, int numberTwo, int numberThree) {
super(numberOne, numberTwo);
this.numberThree = numberThree;
}
public int getNumberThree() {
return numberThree;
}
public void setNumberThree(int numberThree) {
this.numberThree = numberThree;
}
}
Controller
#GetMapping("/a-method")
#JsonView(Views.Public.class)
public ResponseEntity<A> getA(){
return ResponseEntity.ok(new B(1,2,3));
}
#GetMapping("/b-method")
#JsonView(Views.Internal.class)
public ResponseEntity<B> getB(){
return ResponseEntity.ok(new B(1,2,3));
}

Related

how to map json data which has dynamic fields like sku0,sku1 into a pojo class in java

below is my api response
{
"skuInventory": {
"sku0": {
"inventory": {
"PODate": {
"time": 1674363600000
},
"checkBackOrderQTY": false,
"allocatedQuantity": 127,
"endDate": {
"time": 1669216432575
},
"balanceQuantity": 4096,
"ltr60Days": true,
"modifiedDate": null,
"availableQuantity": 0,
"id": "VS-1261",
"dateFirstReceived": {
"time": 1136178000000
},
"totalOnOrder": 4858,
"remainDaysCurrDatePODate": 52,
"pendingBackorders": 0,
"presellFlag": false,
"storeInventory": true
},
"quantityLimitWebPageMsg": "",
"freeShippingPromoAmt": 25,
"notCartableBrandOOSMsg": "",
"cartableFlags": {
"bopusOnlyMessage": "Item is unavailable for shipping, please check local stores for pickup availability",
"ADP": "0",
"BOPUS": "1",
"consumeUpdateFlexShippingVerbiage": "true",
"DTCEstShippingMessage": "Temporarily Out of Stock",
"isProductFlexShippingFeeApplied": "false",
"cartableSku": "1",
"DTC": "0",
"DTCAvailablityMessage": "Temporarily Out of Stock",
"isProductFlexShippingFeeWaived": "false",
"DTCEstShipMsgSiteExp": "Temporarily Out of Stock",
"DTCAvMsgPDPRedesign": "Temporarily Out of Stock"
},
"quantityThreshold": 0
}
}
}
As we can see from above json structure there are multiple properties like sku0,sku1.sku2
I want to convert this json into POJO which i have created which is like below,
public class Root {
private SkuInventory skuInventory;
public SkuInventory getSkuInventory() {
return skuInventory;
}
public void setSkuInventory(SkuInventory skuInventory) {
this.skuInventory = skuInventory;
}
}
public class SkuInventory {
//#JsonAlias({ "sku0", "sku1", "sku2" })
private List<Sku0> sku0;
public List<Sku0> getSku0() {
return sku0;
}
public void setSku0(List<Sku0> sku0) {
this.sku0 = sku0;
}
}
public class Sku {
private Inventory inventory;
private String quantityLimitWebPageMsg;
private int freeShippingPromoAmt;
private String notCartableBrandOOSMsg;
private CartableFlags cartableFlags;
private int quantityThreshold;
public Inventory getInventory() {
return inventory;
}
public void setInventory(Inventory inventory) {
this.inventory = inventory;
}
public String getQuantityLimitWebPageMsg() {
return quantityLimitWebPageMsg;
}
public void setQuantityLimitWebPageMsg(String quantityLimitWebPageMsg) {
this.quantityLimitWebPageMsg = quantityLimitWebPageMsg;
}
public int getFreeShippingPromoAmt() {
return freeShippingPromoAmt;
}
public void setFreeShippingPromoAmt(int freeShippingPromoAmt) {
this.freeShippingPromoAmt = freeShippingPromoAmt;
}
public String getNotCartableBrandOOSMsg() {
return notCartableBrandOOSMsg;
}
public void setNotCartableBrandOOSMsg(String notCartableBrandOOSMsg) {
this.notCartableBrandOOSMsg = notCartableBrandOOSMsg;
}
public CartableFlags getCartableFlags() {
return cartableFlags;
}
public void setCartableFlags(CartableFlags cartableFlags) {
this.cartableFlags = cartableFlags;
}
public int getQuantityThreshold() {
return quantityThreshold;
}
public void setQuantityThreshold(int quantityThreshold) {
this.quantityThreshold = quantityThreshold;
}
}
public class Inventory {
#JsonProperty("PODate")
private Time pODate;
private boolean checkBackOrderQTY;
private int allocatedQuantity;
private Time endDate;
private int balanceQuantity;
private boolean ltr60Days;
private Object modifiedDate;
private int availableQuantity;
private String id;
private Time dateFirstReceived;
private int totalOnOrder;
private int remainDaysCurrDatePODate;
private int pendingBackorders;
private boolean presellFlag;
private boolean storeInventory;
public Time getpODate() {
return pODate;
}
public void setpODate(Time pODate) {
this.pODate = pODate;
}
public boolean isCheckBackOrderQTY() {
return checkBackOrderQTY;
}
public void setCheckBackOrderQTY(boolean checkBackOrderQTY) {
this.checkBackOrderQTY = checkBackOrderQTY;
}
public int getAllocatedQuantity() {
return allocatedQuantity;
}
public void setAllocatedQuantity(int allocatedQuantity) {
this.allocatedQuantity = allocatedQuantity;
}
public Time getEndDate() {
return endDate;
}
public void setEndDate(Time endDate) {
this.endDate = endDate;
}
public int getBalanceQuantity() {
return balanceQuantity;
}
public void setBalanceQuantity(int balanceQuantity) {
this.balanceQuantity = balanceQuantity;
}
public boolean isLtr60Days() {
return ltr60Days;
}
public void setLtr60Days(boolean ltr60Days) {
this.ltr60Days = ltr60Days;
}
public Object getModifiedDate() {
return modifiedDate;
}
public void setModifiedDate(Object modifiedDate) {
this.modifiedDate = modifiedDate;
}
public int getAvailableQuantity() {
return availableQuantity;
}
public void setAvailableQuantity(int availableQuantity) {
this.availableQuantity = availableQuantity;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Time getDateFirstReceived() {
return dateFirstReceived;
}
public void setDateFirstReceived(Time dateFirstReceived) {
this.dateFirstReceived = dateFirstReceived;
}
public int getTotalOnOrder() {
return totalOnOrder;
}
public void setTotalOnOrder(int totalOnOrder) {
this.totalOnOrder = totalOnOrder;
}
public int getRemainDaysCurrDatePODate() {
return remainDaysCurrDatePODate;
}
public void setRemainDaysCurrDatePODate(int remainDaysCurrDatePODate) {
this.remainDaysCurrDatePODate = remainDaysCurrDatePODate;
}
public int getPendingBackorders() {
return pendingBackorders;
}
public void setPendingBackorders(int pendingBackorders) {
this.pendingBackorders = pendingBackorders;
}
public boolean isPresellFlag() {
return presellFlag;
}
public void setPresellFlag(boolean presellFlag) {
this.presellFlag = presellFlag;
}
public boolean isStoreInventory() {
return storeInventory;
}
public void setStoreInventory(boolean storeInventory) {
this.storeInventory = storeInventory;
}
}
Below is the codee to map json into a POJO
ResponseEntity<?> inventoryData = (ResponseEntity<?>) inventoryAPIResponse.getData();
Map<?, ?> inventoryBody = (Map<?, ?>) inventoryData.getBody();
Root atgInventory = getObjectMapper().convertValue(inventoryBody, Root.class);
Sku availableQuantity = (Sku) atgInventory.getSkuInventory().getSku();
If we execute above code we get errors like this
java.lang.IllegalArgumentException: Cannot deserialize value of type `java.util.ArrayList<Sku>` from Object value (token `JsonToken.START_OBJECT`)
at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: Root["skuInventory"]->SkuInventory["sku0"])
How can wee resolve this issue of mapping a json to a pojo which has a property which is dynamic like sku0,sku1,sku2 etc??
I would introduce a Map as follows:
public class Root {
private Map<String, Sku> skuInventory;
}
This Map will then replace your SkuInventory object and has keys like Sku0, Sku1 etc.

415 error while trying to post json array to spring rest controller

My json request is as follows
{
"division":"XX",
"category":"XX",
"operation":"XXX",
"transactionId":"XX",
"trackNumber":"XXx",
"attentionReason":"",
"carNeedAttention":"",
"chargableDamage":"X",
"missingItems":"",
"offences":"N",
"outInAgentNumber":"XX",
"cList":{
{
"id":"230",
"elementCode":"XXX",
"value":"XXX",
"comment":"XX",
"label":"",
"uiComponent":"",
"featureType":""
}
},
"outInCprNumber":"XX",
"outInDate":"",
"outInDuration":"",
"outInFuel":"75",
"outInKm":"9999",
"outInRem1":"",
"outInRem2":"",
"outInRem3":"",
"userName":"XX",
"vehicleRetBy":""
}
I have a spring rest controller class
#Controller
#RequestMapping("/services")
public class CheckListController {
#RequestMapping(value = "/checkList", method = RequestMethod.POST, consumes="application/json",produces="application/json")
public ModelMap updateCheckList(#RequestBody CheckList checkList){
ModelMap modelMap = new ModelMap();
return modelMap;
}
}
CheckList class is as follows
import java.util.List;
public class CheckList {
String division;
String category;
String operation;
String transactionId;
String trackNumber;
String attentionReason;
String carNeedAttention;
String chargableDamage;
String missingItems;
String offences;
String outInAgentNumber;
List<MetaData> cList;
String outInCprNumber;
String outInDate;
String outInDuration;
String outInFuel;
String outInKm;
String outInRem1;
String outInRem2;
String outInRem3;
String userName;
String vehicleRetBy;
String updateMasterImage;
public String getDivision() {
return division;
}
public void setDivision(String division) {
this.division = division;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
public String getTrackNumber() {
return trackNumber;
}
public void setTrackNumber(String trackNumber) {
this.trackNumber = trackNumber;
}
public String getAttentionReason() {
return attentionReason;
}
public void setAttentionReason(String attentionReason) {
this.attentionReason = attentionReason;
}
public String getCarNeedAttention() {
return carNeedAttention;
}
public void setCarNeedAttention(String carNeedAttention) {
this.carNeedAttention = carNeedAttention;
}
public String getChargableDamage() {
return chargableDamage;
}
public void setChargableDamage(String chargableDamage) {
this.chargableDamage = chargableDamage;
}
public String getMissingItems() {
return missingItems;
}
public void setMissingItems(String missingItems) {
this.missingItems = missingItems;
}
public String getOffences() {
return offences;
}
public void setOffences(String offences) {
this.offences = offences;
}
public List<MetaData> getcList() {
return cList;
}
public void setcList(List<MetaData> cList) {
this.cList = cList;
}
// public AccessoryList getAccessoryList() {
// return accessoryList;
// }
//
// public void setAccessoryList(AccessoryList accessoryList) {
// this.accessoryList = accessoryList;
// }
public String getOutInCprNumber() {
return outInCprNumber;
}
public void setOutInCprNumber(String outInCprNumber) {
this.outInCprNumber = outInCprNumber;
}
public String getOutInDate() {
return outInDate;
}
public void setOutInDate(String outInDate) {
this.outInDate = outInDate;
}
public String getOutInRem1() {
return outInRem1;
}
public void setOutInRem1(String outInRem1) {
this.outInRem1 = outInRem1;
}
public String getOutInRem2() {
return outInRem2;
}
public void setOutInRem2(String outInRem2) {
this.outInRem2 = outInRem2;
}
public String getOutInRem3() {
return outInRem3;
}
public void setOutInRem3(String outInRem3) {
this.outInRem3 = outInRem3;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getVehicleRetBy() {
return vehicleRetBy;
}
public void setVehicleRetBy(String vehicleRetBy) {
this.vehicleRetBy = vehicleRetBy;
}
public String getUpdateMasterImage() {
return updateMasterImage;
}
public void setUpdateMasterImage(String updateMasterImage) {
this.updateMasterImage = updateMasterImage;
}
public String getOutInAgentNumber() {
return outInAgentNumber;
}
public void setOutInAgentNumber(String outInAgentNumber) {
this.outInAgentNumber = outInAgentNumber;
}
public String getOutInDuration() {
return outInDuration;
}
public void setOutInDuration(String outInDuration) {
this.outInDuration = outInDuration;
}
public String getOutInFuel() {
return outInFuel;
}
public void setOutInFuel(String outInFuel) {
this.outInFuel = outInFuel;
}
public String getOutInKm() {
return outInKm;
}
public void setOutInKm(String outInKm) {
this.outInKm = outInKm;
}
}
MetaData is as folows
public class MetaData{
Integer id;
String label;
String uiComponent;
String featureType;
String value;
String comment;
String elementCode;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public void setId(int id)
{
this.id = id;
}
public String getLabel()
{
return label;
}
public void setLabel(String label)
{
this.label = label;
}
public String getUiComponent()
{
return uiComponent;
}
public void setUiComponent(String uiComponent)
{
this.uiComponent = uiComponent;
}
public String getFeatureType()
{
return featureType;
}
public void setFeatureType(String featureType)
{
this.featureType = featureType;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public String getElementCode() {
return elementCode;
}
public void setElementCode(String elementCode) {
this.elementCode = elementCode;
}
}
But when i submitting the json request it is giving 415 unsuporrted media type error.
What is wrong with this code. Do anybody havve the answer. Thanks in advance.
Nothing with the code. You just need to make sure that Your POST request has the HTTP Content-Type header set to "application/json".
If you use curl to POST the data you can use the following parameter to set the header value:
curl -H "Content-Type:application/json"
Add an Accept header too:
curl -H "Content-Type:application/json" -H "Accept:application/json"

dropwizard: incorrect json resulting from group of items

I am using Dropwizard to deliver a RESTful service. The JSON I EXPECT looks like this:
{"featuredMerchants":
{"featuredMerchant":[
{"browseId":"v1_0_0_1112",
"merchantId":3902,
"priority":1,
"sourceId":"15"},
...,
{"browseId":"v1_0_0_1112",
"merchantId":456,
"priority":4,
"sourceId":"15"}]}}
But the JSON I am GETTING is this:
{"featuredMerchant":[
{"browseId":"v1_0_0_1112",
"merchantId":3902,
"priority":1,
"sourceId":"15"},
...,
{"browseId":"v1_0_0_1112",
"merchantId":456,
"priority":4,
"sourceId":"15"}]}
I have two classes. I have an ApiFeaturedMerchantGroup class that contains a list of ApiFeaturedMerchants.
#JsonRootName("featuredMerchants")
public class ApiFeaturedMerchantGroup {
private List<ApiFeaturedMerchant> apiFeaturedMerchants;
public ApiFeaturedMerchantGroup() {
}
#JsonProperty("featuredMerchant")
public List<ApiFeaturedMerchant> getApiFeaturedMerchants() { return apiFeaturedMerchants; }
public void setApiFeaturedMerchants(List<ApiFeaturedMerchant> apiFeaturedMerchants) { this.apiFeaturedMerchants = apiFeaturedMerchants; }
}
#JsonRootName("featuredMerchant")
public class ApiFeaturedMerchant {
private String browseId;
private int merchantId;
private Integer priority;
private String sourceId;
public ApiFeaturedMerchant() {
}
public String getBrowseId() { return browseId; }
public void setBrowseId(String browseId) { this.browseId = browseId; }
public int getMerchantId() { return merchantId; }
public void setMerchantId(int merchantId) { this.merchantId = merchantId; }
public Integer getPriority() { return priority; }
public void setPriority(Integer priority) { this.priority = priority; }
public String getSourceId() { return sourceId; }
public void setSourceId(String sourceId) { this.sourceId = sourceId; }
}
How do I get the extra level into my JSON, the "featuredMerchants" group that contains the individual "featuredMerchant" items? Do I have the wrong annotations, or am I missing one/some?
It's a setting on ObjectMapperFactory:
ObjectMapperFactory objectMapperFactory = new ObjectMapperFactory();
objectMapperFactory.enable(SerializationFeature.WRAP_ROOT_VALUE);
objectMapper = objectMapperFactory.build();

Is there a way to skip tests in base classes?

I'm using C# 4.0, Visual Studio 2010 and am annotating my methods/classes with the attributes from the Microsoft.VisualStudio.TestTools.UnitTesting namespace.
I'd like to use inheritance in my test classes where each additional inheritance represents something changing or being created. If I could get it to not run tests from the base classes, then everything would be fine. Here's a rough example:
public class Person
{
public int Energy { get; private set; }
public int AppleCount { get; private set; }
public Person()
{
this.Energy = 10;
this.AppleCount = 5;
}
public void EatApple()
{
this.Energy += 5;
this.AppleCount--;
}
}
[TestClass]
public class PersonTest
{
protected Person _person;
[TestInitialize]
public virtual void Initialize()
{
this._person = new Person();
}
[TestMethod]
public void PersonTestEnergy()
{
Assert.AreEqual(10, this._person.Energy);
}
[TestMethod]
public void PersonTestAppleCount()
{
Assert.AreEqual(5, this._person.AppleCount);
}
}
[TestClass]
public class PersonEatAppleTest : PersonTest
{
[TestInitialize]
public override void Initialize()
{
base.Initialize();
this._person.EatApple();
}
[TestMethod]
public void PersonEatAppleTestEnergy()
{
Assert.AreEqual(15, this._person.Energy);
}
[TestMethod]
public void PersonEatAppleTestAppleCount()
{
Assert.AreEqual(4, this._person.AppleCount);
}
}
I asked a coworker and he suggested separating the initializing code from the testing. Inherit all the setup code, but then place all the tests for a particular setup in a class that inherits from said setup code. So the above would become:
public class Person
{
public int Energy { get; private set; }
public int AppleCount { get; private set; }
public Person()
{
this.Energy = 10;
this.AppleCount = 5;
}
public void EatApple()
{
this.Energy += 5;
this.AppleCount--;
}
}
[TestClass]
public class PersonSetup
{
protected Person _person;
[TestInitialize]
public virtual void Initialize()
{
this._person = new Person();
}
}
[TestClass]
public class PersonTest : PersonSetup
{
[TestMethod]
public void PersonTestEnergy()
{
Assert.AreEqual(10, this._person.Energy);
}
[TestMethod]
public void PersonTestAppleCount()
{
Assert.AreEqual(5, this._person.AppleCount);
}
}
[TestClass]
public class PersonEatAppleSetup : PersonSetup
{
[TestInitialize]
public override void Initialize()
{
base.Initialize();
this._person.EatApple();
}
}
[TestClass]
public class PersonEatAppleTest : PersonEatAppleSetup
{
[TestMethod]
public void PersonEatAppleTestEnergy()
{
Assert.AreEqual(15, this._person.Energy);
}
[TestMethod]
public void PersonEatAppleTestAppleCount()
{
Assert.AreEqual(4, this._person.AppleCount);
}
}
If someone else knows how to skip inherited methods like I originally asked, then I'll accept that. If not, then eventually I'll accept this answer.

Hibernate problem with instruction remove

I have a prbolem with hibernate entitymanager and in particular with the instruction remove.
I try to remove a entity from the db but the system return this error.
ERROR [JDBCExceptionReporter] Cannot delete or update a parent row: a foreign key constraint fails (`datalesson`.`coursematerial_lecture`, CONSTRAINT `FK2471D4A14EC7B08F` FOREIGN KEY (`lectures_id`) REFERENCES `lecture` (`id`))
The line code that generate this errore are this:
private static CleanDatabaseSystemRemote cdsr;
cdsr = (CleanDatabaseSystemRemote) ctx.lookup("CleanDatabaseSystemJNDI");
...
int idCourse = tsr.CreateCourse("Test1", "JUnitTest1", 10, idTrainer);
int idCourseMaterial = tsr.CreateCourseMaterial(idCourse, idTrainer, 1, "CourseMaterial");
int idLecture = tsr.CreateLecture(idCourseMaterial, "Test");
...
cdsr.removeCourseMaterial(idCourseMaterial);
cdsr.removeLecture(idLecture);
cdsr.removeCourse(idCourse);
The CleanDatabaseSystem have:
#Remove
public void removeCourse(int idCourse) {
Course course = new Course();
course = manager.find(Course.class, idCourse);
if(course != null){
manager.remove(course);
}
}
#Remove
public void removeCourseMaterial(int idCourseMaterial) {
CourseMaterial courseMaterial = new CourseMaterial();
courseMaterial = manager.find(CourseMaterial.class, idCourseMaterial);
if(courseMaterial != null){
manager.remove(courseMaterial);
}
}
#Remove
public void removeLecture(int idLecture) {
Lecture lecture = new Lecture();
lecture = manager.find(Lecture.class,idLecture);
if (lecture != null) {
manager.remove(lecture);
}
}
And the entity are
#Entity
public class Course implements java.io.Serializable{
...
#Id
#GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getCredits() {
return credits;
}
public void setCredits(int credits) {
this.credits = credits;
}
#ManyToOne(cascade={CascadeType.ALL})
public Trainer getTrainer() {
return trainer;
}
public void setTrainer(Trainer trainer) {
this.trainer = trainer;
}
#ManyToMany(targetEntity = lesson.domain.Trainee.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
#JoinTable(name="COURSE_TRAINEE", joinColumns= #JoinColumn(name="COURSE_ID", unique=false), inverseJoinColumns=#JoinColumn(name="TRAINEE_ID", unique=false))
public Set<Trainee> getStudents() {
return students;
}
public void setStudents(Set<Trainee> students) {
this.students = students;
}
}
#Entity
#Inheritance(strategy=InheritanceType.JOINED)
public class CourseMaterial extends LearningObject implements java.io.Serializable{
...
#OneToMany(cascade={CascadeType.ALL})
public Set<Lecture> getLectures() {
return lectures;
}
public void setLectures(Set<Lecture> lectures) {
this.lectures = lectures;
}
public String getMaterialName() {
return materialName;
}
public void setMaterialName(String materialName) {
this.materialName = materialName;
}
public void insertLecture(Lecture lecture){
this.lectures.add(lecture);
}
}
#Entity
public class Lecture implements java.io.Serializable {
...
#Id
#GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
#OneToMany(cascade={CascadeType.ALL})
public Set<Papers> getPapers() {
return papers;
}
public void setPapers(Set<Papers> papers) {
this.papers = papers;
}
#OneToMany(cascade={CascadeType.ALL})
public Set<Slide> getSlides() {
return slides;
}
public void setSlides(Set<Slide> slides) {
this.slides = slides;
}
#OneToMany(cascade={CascadeType.ALL})
public Set<Example> getExamples() {
return examples;
}
public void setExamples(Set<Example> examples) {
this.examples = examples;
}
public void insertPapers(Papers papers){
this.papers.add(papers);
}
public void insertSlide(Slide slide){
this.slides.add(slide);
}
public void insertExample(Example example){
this.examples.add(example);
}
}
I don't understand the problem.
Is the cascade? I have miss any annotations?
Thanks
Looks like your course material is referenced from lectures - you'll probably want to remove the lectures first, and the course material second.