1

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

ha9u63a7
  • 6,233
  • 16
  • 73
  • 108
rocking
  • 4,729
  • 9
  • 30
  • 45
  • @ha9u63ar how can this be a duplicate,I am not using hibernate.I am using *JPA* http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManager.html#createNativeQuery(java.lang.String, java.lang.Class) – rocking Jan 23 '15 at 10:16
  • then don't tag your post with Hibernate – ha9u63a7 Jan 23 '15 at 10:18

0 Answers0