-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Question about EntityTransaction - IllegalStateException
PostPosted: Wed Dec 06, 2006 11:08 pm 
Newbie

Joined: Wed Dec 06, 2006 10:52 pm
Posts: 5
MYSQL 5.0

This probably might sound like a beginner's question but I have been wondering on how to get this to work in EJB3. Ofcourse EJB3 uses EntityManager API behind the scenes for Persistence, I would like to know why did code throws an IllegalStateException.

class SomeClass {

@PersistenceUnit
private EntityManagerFactory emf;

.....

public void someMethod() {
EntityManager em = emf.getEntityManager();
ClassB b = new ClassB();
while (someCondition) {
b.setEntityManager(em);
b.call();
}
em.close();
}

} //End of SomeClass

//Begin ClassB
class ClassB {

private EntityManager em;

public void setEntityManager(EntityManager em) {
this.em = em;
}

public void call() {
em.getTransaction().begin();
//doSomething();
em.commit();

}
} // End of ClassB
I have simplified this code not to show any exception handling etc....but I was wondering if there's anything wrong with em.getTransaction().

This is what I understand from the code.

The EntityManagerFactory is created by the container (in this case an EJB3 container). Each single instance of EntityManager is managed by the application and so is the Transaction ??

THats where I am lost ... ANy thoughts?

Thanks
K


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.