• Post Reply Bookmark Topic Watch Topic
  • New Topic

Injecting an EJB into an Automatic Timer EJB returns null  RSS feed

 
Sergio Torassa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to develop e very simple app based on a running thread creating entities in a DB every second in JavaEE on a Glassfish4 Server.

I'm using an Automatic Timer, where I inject an EJB managing the persistence.

The Timer Service is the following one:



While the EJB is:



But when I try to use the MeasureEJB in the UpdateEJB the app stops on the create method with measureEjb=null. What am I doing wrong?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2966
210
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code looks ok.

Did you check your server-log? I suspect that there might be a problem with your PersistenceContext injection.
 
Sergio Torassa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I checked the logs. But the problem cannot be in PersistenceContext, as the EntityManager.persist() method is not even called. As you can see from my post the measureEjb variable is null, when I call measureEjb.create(Measure)
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2966
210
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the problem cannot be in PersistenceContext, as the EntityManager.persist() method is not even called

Yes, but when the MeasureEJB cannot be created it can also not be injected. I tried your code and it is perfectly working in my environment.

Try to put a PostConstruct method for the MeasureEJB:

and do you see the MeasureEJB being created?
 
Sergio Torassa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems the MeasureEJB is not even created, as I don't see any "MeasureEJB Crated!" in the log
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2966
210
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to be sure: both EJBs are deployed in the same package?
It seems the MeasureEJB is not even created, as I don't see any "MeasureEJB Crated!" in the log

Ok, try to remove the JPA dependency, and see if it works:
 
Sergio Torassa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried using the PostConstruct annotation also on the UpdateEJB and I don't find any log as well. So I think there is a more fundamental mistake I'm doing... And there is!! I found that when I deploy my war file in Glassfish the code is not updated. If I delete a System.out.println from the code, make a "mvn package" and then undeploy and redeploy the application, I still see the related logs in server.log Now I should rename this topics in "Issue redeploying war in Glassfish"... What could be the reasons?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2966
210
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm, sounds like there is another Glassfish instance running...
 
Sergio Torassa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to deploy the app in another machine and everything works fine. Now I'd like to understand the strange behaviour in my first machine. I modified a string in my logs and then did a grep -rnw '/path to eclipse project/' -e "old string" and removed all the files. I did a 'mvn package' and deployed in Glassfish the target/<filename.war>. But I still see old logs. Why is Glassfish still keeping old code instead? How can I redeploy from scratch the app?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!