Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jboss7, DAO, JPA, Problem getting transaction (javax.persistence.TransactionRequiredException)  RSS feed

Carsten Negrini
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

hopefully some of you can help me: I want to deploy an application into JBoss7. This app should use Container-managed persistency (JPA). Now the problem is that I can't update the database, because i'm not able to get a transaction.

This is my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns=""
<persistence-unit name="myDS" transaction-type="JTA">

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="" value="myDSEntityManager"/>
<property name="" value="SchemaDSEntityManagerFactory" />
<!-- property name="transaction.factory_class" value="org.hibernate.transaction.JDBCTransactionFactory"/-->
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>

The Entity-classes are defined like this:

@NamedQuery(name="Pricedata.findAll", query="SELECT p FROM Pricedata p")
public class Pricedata implements Serializable {
private static final long serialVersionUID = 1L;

private Integer id;

private String someId;

Now the DAO-classes:

public class PricedataDao implements DaoInterface<Pricedata, String> {

private EntityManager em;
final Logger logger = Logger.getLogger(getClass());
private Context ic = null;

public void init()
try {

if (ic == null)
ic = new InitialContext();
if (em == null || !em.isOpen())
em = ((EntityManagerFactoryImpl)ic.lookupLink("java:/SchemaDSEntityManagerFactory")).createEntityManager();
if (em==null) {
logger.error("EntityManager not set.");
} catch (Exception e) {
logger.error("Error on getting emf: " + e);

public ArrayList<Integer> updateByDto(ArrayList<dto.myPrice> pspList) {

if (em==null) {
logger.error("updateByDto(): not possible, EntityManager not instantiated.");
return null;

ArrayList<Integer> al = null;
String nativeSql = "";
try {
for (int i=0; i<pspList.size(); i++) {
dto.myPrice psp = pspList.get(i);
nativeSql = "insert into schema.Pricedata (id, ....";

Query q = em.createNativeQuery(nativeSql);

int retCode = q.executeUpdate();

The error-message I get while executing q.executeUpdate is an javax.persistence.TransactionRequiredException.
After a few hours of trying i'm now blind to find the problem.
The days before we migrated the whole project from application-managed persistency (getting EntityManagerFactory via Persistence.createEntityManagerFactory()) to CMT.

Hopefully I made a small problem only and you can point me in the right direction.

Best regards, Carsten
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!