Hibernate version: 2.0.0.2002
Sorry if this seems a bit messed but im doing this at speed!
Ok guys, i am sure there is a pretty simple explanation for this one and i am sure other people may have worked this out on their own but i am racking my brains about this one and i kinda have to have this solved by the end of the day........well a few hours.
Everything in NHibernate we have done works perfectly, no problems what so ever. However this is what we are trying to do:
We read some values from another database. For each of these values we need to determine if in one of it's related tables, the values exist...eg:
Read value:
User Entity:
UserID: 0 (new value)
Username: test
Application Entity: (Contains AppID, AppName)
We need to either add a new 'Application' or get an existing one. Generating a new one is not a problem. But this is what we do:
For each record, if the application already exists, we need to fill an Application Entity with this existing application from the database, if not create a new one. So we find that an application specified in our search already exists in the database. So we return for instance:
Application Entity:
AppID: 1
AppName: TestApp
We attach this application entity to our user entity, resulting in thus:
User Entity:
UserID: 0 (new value)
Username: test
Application Entity: (AppID: 1, AppName: TestApp)
Now when it comes to the persist, it fails giving us the following error 'Detached Entity passed to persist'.
So is what i am doing just a misunderstanding of NHibernate? Please bear in mind that i have been given 3 days to learn this, the business objects and code on an existing application so i may have missed a step somewhere.
Any help would be greatly appreciated.
|