Dynamic class generation in combination with O/R
Hello I am not so familiar with reflection, but I read the tutorial on the official Java page.
But what I can't find out is how to do this.
Say I want a class that is central to save all my persistable objects.
So instead of a saveUser, saveProfile, saveMachine, etc. i would only have saveObject.
But how do I do this?
What I want to accomplish is a function that does something like this (using hibernate):
--
public void saveObject( Object object)
{
...//get hibernate session
...
...//do something so that object is cast into either, User, Machine, Profile, etc.
...//so that it becomes object = (<good class name>) object;
...save(object);
...
...//close hibernate session
}
--
So it doesn't know what object it gets, but it should be known through reflection (or is there another way?) what it is.
I have thought about object.getClass() & forName() etc. but they all don't really seem to work for what i want.
Anyone has a suggestion or a solution?
Thank you.
edit:
example of what doesn't work:
...
Machine machine = new Machine();
Object o = machine;
Class c = o.getClass();
c object = (c) o;
...
c.forName("Machine") object;

