Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

[OneToMany ManyToOne] null value in JoinColumn

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
I'm trying to establish a OneToMany relation from a Usr class towards an AddressList class and viceversa ManyToOne. My problem is on the mapped AddressList.user_fk, which should keep the reference, while instead is null ane returns an error from Hibernate:

javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: xx.xxxxx.xxx.UsrAddress.user_fk



My POJO


Any suggestions?
Thanks in advance
 
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alessandro,

The "mappedBy" attribute refers to the name of the field or property in the other class, not the db column, so your OneToMany mapping metadata should be:

@OneToMany(cascade=CascadeType.ALL, mappedBy="user_pk")
 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mike Keith:

@OneToMany(cascade=CascadeType.ALL, mappedBy="user_pk")


you meant "user_fk" ??
I'm still getting the same error

avax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: xx.xxxxxx.xxxxxxx.model.UsrAddress.user_fk



just wondering if the following way to instance the object on the client side may be the reason


It should be, because the other address property are correctly written if I omit the not null annotation.
I'm a bit confused...



Another question, I've understood that mappedBy must refers to the property and not to the DB field, but why on the DB it comes out as user_fk_id, should this field be an integer?
[ June 12, 2007: Message edited by: Alessandro Ilardo ]
 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
aparently I was right, I missed the following line code just before to add the address obj:

address.setUser_fk(user);

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic