How to persist an unmanaged property object
Posted on 2008-10-20
I'm using an EJB 3.0 entity bean.
I want to save a new Employee entity bean and associate it to the department id = 44;
The way it works, I need to
1-fetch the department entity bean
2-Set the department into the employee
3-Save the employee.
If you notice, the first step is useless since I already know the Id of the department. Why should I fetch it and get a managed entity bean?
I would expect to be able to do that kind of save:
Department dep = new Department();
Employee emp = new Employee();
But that doesn't work because the framework forces to have a managed object as the department. I would have thought that when I set CascadeType to nothing it would do the trick but it doesnt.
Is there any workaround for this ?