A transaction will be automatically wrapped around every service builder method that starts with add, update, delete (and I believe create and some others, but don't have a list handy).
To bind all of these into a single transaction, the key is to create one entry point in your XxxLocalServiceImpl class to handle the bulk insert/update:
1public Parent addParentAndChildren(final Parent parent, final List<Child> children) {
2 // persist the parent object the way you normally would
3
4 // handle the children here, whether you do a simple case of deleting the current children and blindly adding the children in the list
5 // or a more complex method of selectively adding, removing, and updating children as given in the list.
6
7 // return the parent instance, this is standard for all add/update operations of Service Builder
8 return parent;
9}
Now when you call ParentLocalServiceUtil.addParentAndChildren(myParent, myChildren), this will all be handled within the scope of a single transaction.
So my original statement of "parent and children must be inserted manually" is still true, it is still up to the developer to manage the inserts.
Please sign in to flag this as inappropriate.