• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to save relational entities in spring Data  RSS feed

 
newone Ji
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.

 
Jayesh A Lalwani
Rancher
Posts: 2762
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!