I'm having a hibernate model. It's quite complex.
The root object in my hierarchy (let's call it a 'user') is really, really big.
There are four objects that are quite independent - Users, Carts, Products and Characteristics.
By independent I mean - no cascading between them.
A User has a collection of Carts, a Cart has a collection of Products, a Product has a collection of Characteristics.
This is a really big simplification. There are a ton of other objects attached to all of the four objects. Cascading was switched on between the objects in the hierarchies of the four main objects.
I had to write a web service that could work with this object model.
I wanted to do something RESTful-like.
I did it like this:
A. I wanted to supply CRUD operations to the four independent objects.
B. Between the independent objects I put only IDs: If you download a Cart you get a collection of Product.id so you can get all the products by using getProduct(id)
'B' proved to make my life a living hell - if you want a Cart, to get the collection of Product.id, I had to get all the Products with its full hierarchy - which is really unnecessary.
Question:
What is the best way to fix that?
Do I have to create getProduct() with no Carts in it and getProducts(Cart c)?
Question2:
When I return a single Product, do I return the Cart associated with it (via Product.getCart())? I don't think so, because then Cart is big. But the client should have a way to know which Product is linked to which Cart.
|