4 Replies Latest reply on Dec 14, 2010 2:06 PM by Chris Williams

    PersistenceContextType.EXTENDED and Transactions

    Chris Williams Newbie

      JBoss 5.1

      JPA 1

       

      The EXTENDED pattern of coding appears to be the model that fits my needs, but I'm having problems finding reference material for it that makes sense and works. As I understand it, every command I make which changes data gets queued up and doesn't commit until I call em.flush(). I've compiled and run like that, but I'm fairly sure that this method has no rollback functionality, which makes it useless for a production environment. All of the reference material that I can find says that you need to call em.getTransaction().begin() to start a transaction, but I get "A JTA EntityManager cannot use getTransaction()" as an error when I try to do that. But where I create my EntityManager like:

       

       

      @PersistenceContext(unitName="MySQL", type=PersistenceContextType.EXTENDED)
      private EntityManager em;

      @PersistenceContext(unitName="MySQL", type=PersistenceContextType.EXTENDED)

      private EntityManager em;

       

       

      The reference material gets it from an EntityManagerFactory. But, it never says where one can get an EntityManagerFactory from. I can inject one via @PersistenceUnit, but there's no option for EXTENDED there.

       

      My book says that I should set the session bean to @TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED) and on a method by method basis set TransactionAttributeType.REQUIRED, but this results in no data being written to the database. With that, I can call em.getTransaction.begin()/commit() without error, but still no data is written to the database. Adding em.flush() doesn't change anything.