yogeshgupte wrote:
is it possible to insert parent when save is called on child? generally we get parent key not found exception when trying to insert child before parent is inserted. In our case we need to avoid exception and make sure parent is inserted for us if missing while inserting child. We can not explicitly handle save order due to abstract offline product functionality.
Hi,
if you want to save a parent entity through a child entity you should use a cascade value of "save" or "save-or-update" (according to your needs) when mapping the parent entity in your child entity. Then if you have defined an auto-generated primary key strategy you shouldn't need to provide a key.
If you want to just save a child which is referencing an already existing parent then your best choice I think is to load the parent first set this to the child and then save the child.
cheers,
mosa