Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

[OneToMany ManyToOne] null value in JoinColumn

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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);

 
Bras cause cancer. And tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic