for the following SFSB:
@Stateful
| @Name("testTransactionsAction")
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public class TestTransactionsAction implements TestTransactionsLocal
| {
|
| @Logger
| private Log log;
|
| @In
| StringUtils stringUtils;
|
| @PersistenceContext
| private EntityManager entityManager;
|
| private String serialNumbers;
|
| private String serialNumber;
|
| /*--------------------------------------------------------------------------BEGIN
METHODS-------------------------------------------------------------------*/
|
| public void searchSerialNumbers()
| {
| //parse serial numbers from HtmlInputTextarea control....
| List<String> serialNumberList = parseSerialNumber();
|
| if (serialNumberList != null && serialNumberList.size() > 0)
| {
| for (String serialNumber : serialNumberList) //persist records one serialNumber at
a time...
| {
| this.persistA();
| String[] sArray = new String[4];
| //cause IndexOutOfBoundsException to see if the first insert will commit or
not....
| String s = sArray[10];
| this.persistB();
| }
| }
| }
|
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public void persistA()
| {
| TestTransactions testTransactions = new TestTransactions();
| testTransactions.setSerialNumber(serialNumber);
| testTransactions.setAddedDate(new Date());
| entityManager.persist(testTransactions);
| //entityManager.flush();
| }
|
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public void persistB()
| {
| TestTransactions testTransactions = new TestTransactions();
| testTransactions.setSerialNumber(serialNumber);
| testTransactions.setAddedDate(new Date());
| entityManager.persist(testTransactions);
| //entityManager.flush();
| }
|
| @Remove @Destroy
| public void destroy() {}
|
| public String getSerialNumbers()
| {
| return serialNumbers;
| }
|
| public void setSerialNumbers(String serialNumbers)
| {
| this.serialNumbers = serialNumbers;
| }
|
| private List<String> parseSerialNumber()
| {
| //parse serialNumber assuming that the regex to use is CR (carriage return), which
will be scan gun post-fire append <ENTER>
| List<String> serialNumberList =
stringUtils.splitAndTrimStringAsArray(serialNumbers, "\\r");
|
| //testing: delete this later...
| if (serialNumberList != null)
| {
| for(String serialNumber : serialNumberList)
| {
| log.info("parseSerialNumber(): serialNumber = "+serialNumber);
| }
| }
| return serialNumberList;
| }
|
| }
|
I'm getting this exception in persistA() method. Why does this happen? What are the
rules for tx propagation in JBoss/EJB3? I was expecting there to be a tx active in
persistA() due to the REQUIRED tx type. The goal here is to persist the record prior to
the exception being thrown and thus not rollback any tx (which should not exist for the
searchSerialNumbers() method as the tx type is marked NOT_SUPPORTED for the class which
should default to auto commitmode, as per pg. 512 of Bauer/King book. It doesn't
matter if I use private or public visibility for the persistX() methods, same result. No
records are inserted to the db table either way. thx.
Caused by: javax.persistence.TransactionRequiredException: EntityManager must be access
within a transaction
| at
org.jboss.ejb3.entity.ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.java:156)
| at
org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:189)
| at
org.jboss.seam.persistence.EntityManagerProxy.persist(EntityManagerProxy.java:135)
| at
com.cox.bets.session.TestTransactionsAction.persistA(TestTransactionsAction.java:86)
| at
com.cox.bets.session.TestTransactionsAction.searchSerialNumbers(TestTransactionsAction.java:61)
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4219580#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...