I have a distributed System in which the Client can create some new Entities.
Those Entities by default have no Identifier so I call a remote Method of my Application Server to save the Object to Hibernate.
As a return the Client receives the positive Identifier on success and can set it and so the client made sure the Server App has saved the Object.
Else no Client Entity-Object would be created.
This is realized with a method which is called from the remote bean:
Code:
public int saveObj(Obj obj)
{
//...
return (Integer)session.save(obj);
}
This works fine aslong I know that the object is new.
Now I have a Entity with some relations so that I need to save or update some relational Entities.
But i cannot receive the id anymore since saveOrUpdate() returns void.
I maybe could return the saved Object, but that would be much more overhead instead of an primitive int, or I would need a cast to the specific Entity to return the identifier field. Or use reflection.