Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[OneToMany ManyToOne] null value in JoinColumn

 
Alessandro Ilardo
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
 
Mike Keith
author
Ranch Hand
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);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic