I am using JPA native query method for inserting I have requirement where I have to insert multiple rows in a table based on the size of a list
For now I am doing like the following
Inside service
public int insertQuery()
{
int size=list.getEmplyees();
int value=//here I am connectiong dao class and getting value
for(int i=0;i<size;)
{
String insert="insert into tab(id,value) values("+id+")"
//here I am sending this query to dao class
int result=dao.insertQuery(insert);
if(result>0)
{
i++;
}
}
inside dao class
public int insertQuery(String query)
{
Query q=entimanagerutil.createNativeQuery(query);
return q.executeUpdate();
}
I am sure this is one of the worst way of programming,so can you guys please suggest me how to insert in a batch or suggest me some good ways