• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem trying to create my EntityManagerFactory

 
Frederico Benevides
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having problem to create my entitymanagerfactory with jboss 4.2.0.

It's saying this "The chosen transaction strategy requires access to the JTA TransactionManager"

The problem happens in this line "EntityManagerFactory emf = Persistence.createEntityManagerFactory("testJPAEJB3");"

This problems doesn't happen when I use @PersistenceContext.

My persistence.xml



my datasource only have the connection, no more property.

Thank you.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am assuming that you are doing in-container persistence.

What if you use something like below instead?

@PersistenceUnit(unitName="xxxx") private EntityManagerFactory factory;
@PersistenceContext(unitName="xxxx") private EntityManager manager;

If it is out-of-container, try adding the properties.
 
Frederico Benevides
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the answer.

Yes I'm doing in container persistence. Using @PersistenceContext works without problem, without changing anything in my persistence.xml.

But I would like to try to access my persistence using this: "EntityManagerFactory emf = Persistence.createEntityManagerFactory("testJPAEJB3");". Just to study others ways to do the same thing, and to learn too.

Thank you.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In-container, I think you can get the factory only via jndi or injection (annotation or xml injection).

By doing that way you showed, I believe you are doing out-of-container persistence. Even if you are running in the container, you are not using the container's persistence. You wouldnt usually want to do that, unless you really intend to (e.g. you are on a plain jse platform), as you wont be getting the benefits of the container. E.g., you have to call close() yourself on the factory, which jee does in-container.

If you still want to do it, you may need to use RESOURCE_LOCAL transactions, and yes, manage your own transactions, instead of the container doing it for you.
 
Frederico Benevides
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I understood now. Thank you!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the ORM forum. New EJB3 EntityManager etc, that are about JPA go into that forum.

Thanks

Mark
 
Ankur .Jain
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am getting the same problem. I want to use it as in-container. But want to keep EntityManager logic in separate class(not an Session Bean). I doesn't want to use Dependency Injection either (Due to some project constraints).

The code which I have wrote is :


How can I resolve this problem without changing persistence.xml or <databse>-ds.xml file.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean, like, get the factory using jndi?

If so, try look at this, which I found using google.

http://forums.java.net/jive/thread.jspa?threadID=16808
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic