Hibernate Child table saves null foreign key instead of auto increment parent's primary key <p>I'm trying to save to two parent and child table at the same time. It does save the both parent and child rows but the issue is child table doesn't contain the primary key(Auto Increment) of parent table in foreign key column in child table. Instead of that foreign key column in child table shows null</p> <p>here are the Models 01.Feed Order class (Parent Class)</p> <pre><code>@Entity public class FeedOrder { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; private String date; private double total; private double discount; @OneToMany(mappedBy="feedOrder",cascade = CascadeType.PERSIST) private List&lt;FeedOrderDetail&gt; feedOrderDetail; @ManyToOne private Supplier supplier; //With Getters and Setters } </code></pre> <p>02.Feed Order Details class (Child Class)</p> <pre><code>@Entity public class FeedOrderDetail { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private double unitPrice; private long quantity; @ManyToOne @JoinColumn(name="feed_id") private Feed feed; @ManyToOne @JoinColumn(name="order_id") private FeedOrder feedOrder; //With Getters and Setters } </code></pre> <p>I use Spring MVC as well.</p> <p>Here is the Repository class Code.</p> <pre><code>@Repository("feedOrderRepository") public class FeedOrderRepositoryImp implements FeedOrderRepository { @PersistenceContext private EntityManager em; public FeedOrder save(FeedOrder feedOrder) { em.persist(feedOrder); em.flush(); return null; } } </code></pre> <h2>Update</h2> <p>AddFeedOrder.jsp</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;form:form commandName="feedOrder"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Date&lt;/td&gt; &lt;td&gt;&lt;form:input path="date" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Discount&lt;/td&gt; &lt;td&gt;&lt;form:input path="discount" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Total&lt;/td&gt; &lt;td&gt;&lt;form:input path="total" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Supplier&lt;/td&gt; &lt;td&gt;&lt;form:input path="supplier.id" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table id="mytable"&gt; &lt;tr&gt; &lt;td&gt;Feed ID&lt;/td&gt; &lt;td&gt;Unit Price&lt;/td&gt; &lt;td&gt;Quantity&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;form:input path="feedOrderDetail[0].feed.id" /&gt;&lt;/td&gt; &lt;td&gt;&lt;form:input path="feedOrderDetail[0].unitPrice" /&gt;&lt;/td&gt; &lt;td&gt;&lt;form:input path="feedOrderDetail[0].quantity" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;INPUT type="button" value="Add More" onclick="addRow('mytable')" /&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" value="Save Feed Order"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/form:form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>