Hi,
I am running into a much discussed error with a one-to-one mapping, but I just can't getting fixed! I keep running into the following error:
Exception in thread "main" org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [nl.xx.yy.zz.model.UserSession.user]
I am trying to tie a UserSession to an AbstractUser in a one-to-one relationship using a foreign key association.
This is the mapping for the AbstractUser:
This is the mapping for the UserSession:
And this is the code I use:
This throws the "attempted to assign id from null one-to-one property" error. Do you know why and how to solve this? The problem occurs on the session.update(user). All the surrounding code works fine.
Also, when I use session.save() instead of session.update, Hibernate tries to insert a new AbstractUser record with the same id, resulting in a PK constraint failure. Why is Hibernate tryuing to insert a new record instead of just updating the existing one?