This week's giveaway is in the Spring forum.
We're giving away four copies of Microservices Testing (Live Project) and have Chris Love & Andres Sacco on-line!
See this thread for details.
Win a copy of Microservices Testing (Live Project) 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

Value for JoinColumn in ManyToOne is getting inserted as Null

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Q1) Null value is getting inserted for a @JoinColumn in case @ManytoOne RelationShip.

Relation:One User can have Many Vehicles;



Vehicles.java





UserDetail.Java






HibernateTests.java





UserDetail table output

userId User
1 First User




vehicles table output

VehicleId VehicleName user_id
1 Car Null
2 Jeep Null


Q2)Please help me why null is getting is inserted?





 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess would be that this due to the fact that you save Vehicule and UserDetail in the same transaction while both are still transient objects.
Hibernate resolves the associations with persistent objects.

What I would suggest is for you to persist first UserDetail and flush or commit.
After attach to your new Vehicule the persistent UserDetail and then persist vehicule flush/commit.

in theory that should work
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic