am using JPA 2 and EJB 3.1
Have the following Entity:
@Entity
public class SVPDiscovery implements Serializable {
private static final long serialVersionUID = 1L;
public SVPDiscovery() {
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private String objectID;
//bi-directional many-to-one association to Party
@ManyToOne
@JoinColumn(name="EPCISREPOID")
private EpcisRepository EPCISREPOID;
@ManyToMany (cascade=CascadeType.ALL)
@JoinTable(name = "SVPDiscovery_ACL"
, joinColumns = { @JoinColumn(name = "SVPDiscoveryID") }
, inverseJoinColumns = { @JoinColumn(name = "ACLID") })
private List<Party> acl;
}
DAO:
@SuppressWarnings("unchecked")
@JPAManager(targetEntity = svp.poc.entities.SVPDiscovery.class)
public class SVPDiscoveryDAO {
private EntityManagerFactory emf;
@PersistenceContext(unitName= "svp-poc")
EntityManager em ;
public SVPDiscoveryDAO() {
}
private EntityManager getEntityManager() {
if (emf == null) {
throw new RuntimeException(
"The EntityManagerFactory is null. This must be passed ito the constructor or set using the setEntityManagerFactory() method.");
}
return emf.createEntityManager();
}
@Action(Action.ACTION_TYPE.CREATE)
public void addSVPDiscoveryService (SVPDiscovery svpDiscovery){
em = getEntityManager();
try {
em.merge(svpDiscovery);
em.flush();
}catch (Exception ex) {
throw ex;
}finally {
}
}
persistence.xml:
<persistence-unit name="svp-poc" >
<jta-data-source>jdbc/svp-poc-db</jta-data-source>
<mapping-file>META-INF/named-queries.xml</mapping-file>
<class>svp.poc.entities.Location</class>
........
</persistence-unit>
Then when i persist an instance of SVPDiscovery it gives me the follwoing exception :
Caused by: org.apache.openjpa.persistence.TransactionRequiredException: Can only perform operation while a transaction is active.