Package javax.persistence

Examples of javax.persistence.EntityManager.joinTransaction()


        String result = null;
        EntityManager em = null;
        try {
            em = emf.createEntityManager();
            utx.begin();
            em.joinTransaction();
            ourGuy = em.find(Patient.class, patientid);
            if(ourGuy != null) {
                result = ourGuy.getDob();
            }
            utx.commit();
View Full Code Here


        String result = null;
        EntityManager em = null;
        try {
            em = emf.createEntityManager();
            utx.begin();
            em.joinTransaction();
            ourGuy = em.find(Patient.class, patientid);
            if(ourGuy != null) {
                result = ourGuy.getSsn();
            }
            utx.commit();
View Full Code Here

        String result = "";
        EntityManager em = null;
        try {
            em = emf.createEntityManager();
            utx.begin();
            em.joinTransaction();
            Query query = em.createQuery("SELECT d FROM Diagnosis d WHERE d.patientid = :patientid");
            query.setParameter("patientid", patientid);
            List<Diagnosis> diags = query.getResultList();
            if (diags != null) {
                for (Diagnosis diag : diags) {
View Full Code Here

        transactionTemplate.execute(new TransactionCallback<Object>() {
            public Object doInTransaction(TransactionStatus status) {
                // make use of the EntityManager having the relevant persistence-context
                EntityManager entityManager2 = receivedExchange.getIn().getHeader(JpaConstants.ENTITYMANAGER, EntityManager.class);
                entityManager2.joinTransaction();

                // now lets assert that there are still 2 entities left
                List<?> rows = entityManager2.createQuery("select x from MultiSteps x").getResultList();
                assertEquals("Number of entities: " + rows, 2, rows.size());
View Full Code Here

             * Since the Entity Manager (EM) is not managed by the container the developer must explicitly tell the EM
             * to join the transaction. Compare this with ManagedComponent where the container automatically
             * enlists the EM with the transaction. The persistence context managed by the EM will then be scoped
             * to the JTA transaction which means that all entities will be detached when the transaction commits.
             */
            entityManager.joinTransaction();

            // make some transactional changes
            String result = updateKeyValueDatabase(entityManager, key, value);

            /*
 
View Full Code Here

      final EntityManager em = getEntityManager(session);
      Boolean commitStatus = session.getState().getAttributes().getBoolean("commit");
      if (Boolean.TRUE.equals(commitStatus)) {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
          protected void doInTransactionWithoutResult(TransactionStatus status) {
            em.joinTransaction();
          }
        });
      }
      unbind(em);
      em.close();
View Full Code Here

        // Initialized persistence/tx's and persist to db
        EntityManager em = emf.createEntityManager();
        em.setFlushMode(FlushModeType.COMMIT);
        UserTransaction tx = findUserTransaction();
        tx.begin();
        em.joinTransaction();
        em.persist(badMainObject);
       
        boolean rollBackExceptionthrown = false;
        try {
            tx.commit();
View Full Code Here

        mainObject.setName("main" + testName);
        mainObject.setSubObject(subObject);
       
        // Now persist both..
        tx.begin();
        em.joinTransaction();
        em.persist(mainObject);
        em.persist(subObject);
       
        try {
            tx.commit();
View Full Code Here

        return "post-remove";
    }
   
    public void testPostRemoveInvokedOnlyAfterDatabaseDeleteWithLogicalFlush() {
        EntityManager em = emf.createEntityManager();
        em.joinTransaction();
        PostRemoveCallbackEntity pc = new PostRemoveCallbackEntity();
        em.persist(pc);
        em.flush();
        em.remove(pc);
        commit();
View Full Code Here

                && pc.getPostRemoveTime() <= System.nanoTime());
    }
   
    public void testPostRemoveInvokedAfterDatabaseDeleteWithoutFlush() {
        EntityManager em = emf.createEntityManager();
        em.joinTransaction();
        PostRemoveCallbackEntity pc = new PostRemoveCallbackEntity();
        em.persist(pc);
        em.remove(pc);
        assertFalse("PostRemove called before commit", isPostRemovedInvoked(pc));
        commit();
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.