How to insert multiple rows in a table by using hibernate
I have a table called book_chapter.It contains book_id and chapter_id as columns.
I have mapped this table to an entity called BookChapter.
Book and Chapter relationship is coming from GUI.
One book may have many chapters.I have to insert all the rows coming from GUI into book_chapter table.
One way of doing this is to insert one - by one as below :-
BookChapter bc = new BookChapter() ;
bc=new BookChapter() ;
and so on.........
Is there any way I can do this by writing save method only once?
I am looking for something like this :-
List<BookChapter> bookChapterList = new ArrayList<BookChapter>() ;
BookChapter bc1 = new BookChapter() ;
BookChapter bc2 = new BookChapter() ;
I tried passing List object to save method as above but it does not work.Does anyone know of any utility method which does this sort of thing?
if you can use hibernateTemplate instead of session then you can save your object list by using saveOrUpdateAll(Collection entities).