Q:

No transaction is currently active

so i have this code here
User us = new User();
            us.setId(id1);
            us.setUsername(userNameTextField.getText());
            us.setPassowrd(passwordFormattedTextField.getText());
            us.setLevel(levelComboBox.getSelectedItem().toString());
            us.setEmpid(getCurrentEmp());
            getCurrentEmp().getUserCollection().add(us);
            em.getTransaction().begin();               
            em.persist(getCurrentEmp());
            em.flush();
            em.getTransaction().commit();

but when i try to commit i get this error
Exception Description: No transaction is currently active
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionWrapper.throwCheckTransactionFailedException(EntityTransactionWrapper.java:87)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionWrapper.checkForTransaction(EntityTransactionWrapper.java:50)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.checkForTransaction(EntityManagerImpl.java:2015)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:846)

and i dont get y since i have called the entitymanager instance as follows
em = emi.getInstance();

from this class
public class EmInstance {
EntityManager em;
public EntityManager getInstance(){
em = Persistence.createEntityManagerFactory("samplePU").createEntityManager();
return em;
} 

}
My question is how can i make the transaction active whenever i want to use it e.i when committing,updating or any other transaction process. Am using eclipselink and its a desktop application

A:

Are you sure that calling em.getTransaction() those two times gives you back the same transaction?
Try with:
EntityTransaction etx = em.getTransaction();
etx.begin();
...
etx.commit();

