This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Originally posted by John King: Somehow, JBoss did not inject entity manager in my DAO so I got a nullpointer exception when I access the entity manager.
Not always. I've used OpenJPA in JBoss. However, since OpenJPA is not part of the container, I used Spring to instantiate the EntityManager. The injection of the EntityManager is done by the weaver, if I'm not too confused here.
The main thing is that the app has to have some specific sort of persistency framework mechanism defined for it - not just the rules that the framework will be using.
Customer surveys are for companies who didn't pay proper attention to begin with.
Not always. I've used OpenJPA in JBoss. However, since OpenJPA is not part of the container, I used Spring to instantiate the EntityManager. The injection of the EntityManager is done by the weaver, if I'm not too confused here.
Valid point. The application server itself is not going to inject the EntityManager, in components other than EJB. Frameworks like Spring (which i don't have an experience on) are capable enough to inject these dependencies.
Originally posted by John King : The DAO class is called by a stateless EJB so it is part of the EJB.
John, the application server is going to parse the EJB class to scan for any resources which have to be injected. However, its not going to scan the classes which are used in the EJB. The DAO is just being used by the EJB and is not an EJB in itself.
John King
Ranch Hand
Joined: Aug 27, 2002
Posts: 165
posted
0
Originally posted by Jaikiran Pai:
John, the application server is going to parse the EJB class to scan for any resources which have to be injected. However, its not going to scan the classes which are used in the EJB. The DAO is just being used by the EJB and is not an EJB in itself.
I actually changed the code so the EntityManager is defined in the EJB:
@Stateless public class MyServiceBean implements MyServiceRemote { @PersistenceContext(unitName="my_unit") EntityManager entityManager;
//business methods... ... }
When I tried to access the entityManager in business methods, it is still null.
I actually changed the code so the EntityManager is defined in the EJB:
@Stateless public class MyServiceBean implements MyServiceRemote { @PersistenceContext(unitName="my_unit") EntityManager entityManager;
//business methods... ... }
When I tried to access the entityManager in business methods, it is still null.
That's strange. On the same 4.2.2 version of JBoss, i have several such examples where the entitymanager is injected in the EJBs. Do you see any exceptions during deployment? And can you post the logs when your application is being deployed? Also, does changing the injection to
work?
John King
Ranch Hand
Joined: Aug 27, 2002
Posts: 165
posted
0
My bad. It was because of a typo. It works now. Thank Jaikiran.
Douglas Boff Nandi
Ranch Hand
Joined: Feb 25, 2008
Posts: 34
posted
0
Hi
How do you solve this problem? I have the same problem now.
Thank you
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Got NullPointer exception when injecting EntityManger