On 15/09/2010 9:43 PM, glassfish_at_javadesktop.org wrote:
> Description: Here is a for loop. that means if 'for loop' is running 5 times - there will be 5 times insert/update in a same table. Parameters of the function are array of string.
> But i bring 3 sets of data in array of string - that means for loop will run 3 times - and it should 'insert' 3 times in same table simultaneously. but interestingly it is inserting just for first time and ignoring others. But i have checked that value is changing for every time.
You must create a new instance of "Daily_inventory" for every one that
you want to persist. This won't work:
Daily_inventory c = new Daily_inventory();
for (...) {
...
em.persist(c);
}
You need to do this if you want to insert a bunch of new entities:
for (...) {
Daily_inventory c = new Daily_inventory();
...
em.persist(c);
}
To understand why, you really need to read the JPA 2.0 documentation
and/or some introductory books or tutorials on the subject. It will help
to realize that after you call persist() on it, an entity doesn't go
away; it remains attached to the entity manager.
Your question wasn't all that clear, so maybe I'm misunderstanding your
question and answering the wrong thing. Your code appears to be
incomplete (the "//update" block is empty) and I'm not completely sure I
understand what you're getting at.
--
Craig Ringer
Tech-related writing at http://soapyfrogs.blogspot.com/