• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Unable to build EntityManagerFactory

Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've assembled a JSF application with JPA in Eclipse deploying this as a WAR file into JBoss 5. I'm not using EJB.
I created a Managed Bean that calls a DaoFactory that works with JPA to do my database transactions.
When this DaoFactory is created, an EntityManager is created holding it as an instance variable of my DaoFactory, such demonstrated below:

When a Dao is created, the EntityManager instance is passed through a constructor as follows:

The problem is: The EntityManagerFactory can't be created such as JBoss output said:

Unable to build EntityManagerFactory
org.hibernate.HibernateException: The chosen transaction strategy
requires access to the JTA TransactionManager

My persistence.xml was:

So, to solve that problem I changed the transaction-type to RESOURCE-LOCAL, and instead of using jta-data-source I started using non-jta-datasource
which is demonstrated below:

Now, the application works well creating the EntityManagerFactory and so I can persist my data.

I'd like to know why it happens with JBoss.
Does JTA cannot be used when I deploy like a WAR app? Does JTA only works with EJB?

Thanks in advance.

Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adolfo,

I remember using Tomcat for running EJB's for experimental purposes and used a container managed entity manager. But since tomcat is not a EJB server, i had to use the JBoss embedded server for it. Using container managed transactions for an application that does not use EJB's seems quite out of place. If one could do that then one could just make any web app and leave the transaction management issues to the container, making life a lot easy(at least for small applications).

I think that the using container managed transactions and entitymanagers is closely bound to EJB's because the container knows about the life cycle of the EJB's and is in absolute control of their creation/access/destruction have complex processes to handle their memory issues. Quite unlike your own classes that would always be at the mercy of your mind. Its like you sacrifice the control over your classes to gain privileges like container managed transactions. But i dont know for sure what's the reason.

If there is a way to use container managed transactions elsewhere, i would certainly like to know how to do that as well.

Ryan Sukale
    Bookmark Topic Watch Topic
  • New Topic