raunak saxena wrote:
IS there any way, when I save employee object then it’s associated department object is automatically saved provided it’s not there department table previously?
Yes, there is: cascading. And it should work in your example, because you've mapped the department with cascade="all" in your employee entity. Why isn't it working? I see one major thing that you're doing wrong: you're manually setting the identifier values in the employee and the department.
Since you've set up the generators for both of them, just let them do their job ;-) You should leave the identifiers at 0, because that's what you've declared as the unsaved-value.
But then... I bet it'll throw another exception, related to the order in which you're finishing the transaction. If it does, you'll probably figure out why.