Reputation: 106
i am writing hibernate queries in java..
In my application i have user and his business partner as another user.
when a user is created he can select the already existing partner as another user.
new user object has not been created so it is null
user.setUserId(null)//as hibernate automatically increment the userId value
anotheruser.setPartnerId(user.getUserId())
userSet.getPartners.add(user);
session.save(userSet);
It is showing the transientobjectexception..
i think it is because as the primary key is not yet assigned before save thats why it can not setpartnerid there..can anybody give suggestion how best way to implement this..
thanks
Upvotes: 0
Views: 55
Reputation: 7459
Try saving user
before you save userSet
. My guess would be that cascading saves are not configured for that collection, so you are trying to save a link to an unsaved transient reference (user).
You should add your entity classes and mappings to the question, otherwise it's all guesswork!
Upvotes: 1