Hi Rahul,
First I would look at the relationship you have there. You have a situation where an Order can have 0 to many OrderItems. So obviously, you would like to see the OrderItems belonging to an order.
Does the same hold true for an OrderItem. When you have an OrderItem object, do you need to know the Order to which it belongs. As in, is there ever going to be a time when you have an OrderItem first and need to find the Order from which it came. I would suggest that this is unlikely.
The annotations, I tend to put above the declaration of the fields as I find it much easier to read as well. But that is a personal preference.
Here is a way
you should be able to achieve what you are chasing:
In the Order class you would have as follows:
And in your OrderLineItem class, I wouldn't make any reference to your Order class as you should not have a situation by where you need to find the Order to which an OrderLineItem belongs. This is information you should always have as it should be the Order you retrieve/create first.
Note, I have suggested a lazy loading of the OrderLineItems. This means that if you read the Order from the database, the OrderLineItems will not be read unless you initialise the orderItemList before closing the selection transaction. A simple order.getOrderItemList().size(); is enough to initialise it.
Hope this helps.
Regards
Matt Gaunt