JBoss Seam cannot create Java Persistence Entity Manager

295 Views Asked by At

I am at a complete loss with this one. I am scouring the Internet via Google to try and find a solution for this problem. I haven't used JBoss in a very long time, and we use Seam version 2 ... not sure what exact version. I've never used Seam before, so I don't know anything about this framework. My boss wrote most of this code, but he has moved beyond looking at this code, and has tasked me to fix this problem.

So, the problem is ... A user is logged into our Seam app, everything is fine, but when we try to load users from a CSV file, it's as if Seam forgets who we are, and then we get an error.

We have a UserIdentity class starts off like:

@Name("org.jboss.seam.security.identity")
@Scope(ScopeType.SESSION)
@Install(precedence = Install.APPLICATION)
@BypassInterceptors
@Startup
public class UserIdentity extends Identity {

In this class, we have one line of code:

EntityManager entityManager = (EntityManager)Component.getInstance("entityManager",true);

That is returning null, and hence we get an NullPointerException (NPE).

I presume that "Component.getInstance" fails, and it would be nice if we could refresh this and get it back again. It would be great if I could update to a newer seam jar and fix this.

I will continue to scour the Internet for a fix, but in the meantime, if someone has seen this issue, and knows how to fix it, that would be great. Thanks!

1

There are 1 best solutions below

0
On

When you use Component.getInstance method is used to get a reference to a Seam session bean component.

True end your context and creates again. As it is not finding that context It is returning null.

As the EntityManager is used in Session Scope, You don't have to Create it again.

Simple you can inject entity manager as,

EntityManager entityManager = (EntityManager)Component.getInstance("entityManager");

or

@In EntityManager entityManager;