This content has been marked as final.
Show 2 replies
-
1. Re: FlushModeType
herberson Jul 12, 2010 3:36 PM (in response to fjkjava.febinjk.gmail.com)In cases like yours I call flush after the loop, like this:
for (read Parent from excel) { entityManager.persist(Parent) for (read Child from Excel) { entityManager.persist(Child) } } entityManager.flush()
-
2. Re: FlushModeType
shavo26 Jul 12, 2010 7:38 PM (in response to fjkjava.febinjk.gmail.com)This scenario depends on how your transactions are managed and whether or not your your persistence context is scoped to conversation.
Seam reference documentation states:
By default, the persistence context is flushed (synchronized with the database) at the end of each transaction.
This is sometimes the desired behavior. But very often, we would prefer that all changes are held in memory and
only written to the database when the conversation ends successfully. This allows for truly atomic conversations.
If i understand this correctly its 1:N relationship//First persist parent entityManager.persist(Parent) //Set parent id on child child.setParent(Parent) //Persist the child entityManager.persist(Child) //At the end of conversation then flush your changes entityManager.flush()
Take a look at:
Seam-managed persistence contexts and atomic conversations
hereAlso read hibernate entity manager reference documentation
here