This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
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

How to save relational entities in spring Data

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one table called Message and another table called MessageText, and relation for 2 tables is one to many.
I created entity for each table.


and


and I also have a MessageRepository which is the repository for Message Entity, it has method save(Message m).
For test part, I populated each field of Message and MessageText entity, for the join column messageid, I set it to be the same for them,
then call MessasgeRepository.save(Message);
but it always complain that the messageid in Table MessageText can not be null.

 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't have messageid in the MessageText class. Look at this example that shows you how to do a OneToMany mapping
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic