I have Spring MVC web-application. I want to use Hibernate and AJAX. There are two entities: Item and CatalogItem. Entity CatalogItem contains some fields and reference to Item.
It is possible using AJAX to create CatalogItem? With plain objects i have no problems, but with nested.. I want something like this: POST-request from jQuery:
$.ajax({
'type': 'POST',
'url': myurl,
'contentType': 'application/json',
'data': JSON.stringify({'count':10,'deliveryTime':'2012-12-12T12:12:12',
'itemId':{'name':'name','price':100,'description':'qwerty'}}),
'dataType': 'json',
'success': function(){
//
}
});
In spring controller:
@RequestMapping(value = "/add", method = RequestMethod.POST)
public void addItem(@RequestBody CatalogItem catalogItem) {
catalogDAO.addCatalogItem(catalogItem);
}
But this does not work. It throws
[Request processing failed; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: entities.CatalogItem.itemId] with root cause
org.hibernate.PropertyValueException: not-null property references a null or transient value: entities.CatalogItem.itemId
Can you help me?