A session (in the JPA persistence context , which is bound to an EntityManager instance), is a snapshot of the "in memory" state of a subset of the database schema. The volume of your session will vary depending on your configuration. In a standard web application, you will have one session for each request.
You can have many instances of a session with a different state at the same time, the session is isolated from each other (the operation performed in the session does not appear in another)
A transaction is a unit of work (theoretically, a session too). It is tied to the RDBMS core transaction system and tied to the session in which it was opened.
In the context of the “Managed Container Manager” (that you are invoking CMT), the container will associate your session with a specific area and propagate transactions according to the @Transactional annotation @Transactional when invoking methods.
Actually what happens: your container maintains a session instance somewhere and can provide it to your ejb instance using the @PersistenceContext annotation. You manually create a new instance of the session using sessionFactory.openSession() , open a transaction, and perform your operations. A managed session instance cannot see any of these changes until you complete the transaction, manually reset or close your own session and manually activate the update on the container.
The getCurrentSession() method is a hibernation mechanism that acts as a mechanism for managing the container session area in the context of Java SE (without the container). I suppose (but I have no idea about implementing a sleeping JPA) that it will not return a container managed session, but I could be wrong about this. ( change )
The right solution here would be to retrieve the current instance of the container-managed session using @PersistenceContext and control the propagation of transactions using the @Transactional annotation.
See https://community.jboss.org/wiki/SessionsAndTransactions
See Luk's comment below
FYI See Container Managed Transactions
EDIT (according to issue questions)
See The Difference Between "jta-datasource" and "Resource-Local" DataSource?
It actually seems like I was wrong and that you don't need to use persistence context wrap from the container, but you MUST use JTA transactions.
From the EJB 3.0 Specification, Section 13.3.4 Beans Enterprise Using Managed Container Transaction Demarcation:
The enterprise bean's business methods [...] must not attempt to obtain or use the javax.transaction.UserTransaction interface.
That means you can use
sessionFactory.getCurrentSession()
but you should not use tx = session.beginTransaction (), but instead
@TransactionAttribute(TransactionAttributeType.REQUIRED)
See transaction demarcation with the EJB / CMT section in the jboss document above