0

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?

1
  • You are trying to save a CatalogItem without first saving an Item. Commented May 23, 2012 at 20:34

1 Answer 1

2

You are trying to save a CatalogItem without first saving an Item.

Without seeing your mappings it's hard to say otherwise.

Read the Hibernate docs on cascading.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.