• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Help HIGHLY needed with one-to-one mapping error

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ruben,

Your save operation is working fine but exception is throw in update operation because of sessionId property of UserSession object store the null value.

Save() operation is working fine because hibernate generate the incremented value for sessionId property but this is not true about update() operation. You should explicitly assigned the sessionId value. If I am not wrong then get the value from userlist and assigned to the sessionId property.

If you have any query/exception regarding this suggestion please inform me.

Thanks&Regards
Devarshi
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic