Is there any way to inject @Named bean to Singleton?
Here's the class that needs to be injected
@Named
@Stateful
@ConversationScoped
public class PlaySessionBean implements Serializable {
@PersistenceContext(unitName = "test-persistence-unit", type = PersistenceContextType.EXTENDED)
private EntityManager entityManager;
....
}
The bean is used for view utility (generated by Forge)
The problem is that I need to access the PlaySessionBean
from @Startup @Singleton
@Startup
@Singleton
public class StartupBean {
private static final Logger LOGGER = Logger.getLogger(StartupBean.class.getName());
private EntityManager entityManager;
private static EntityManagerFactory factory =
Persistence.createEntityManagerFactory("wish-to-paris-persistence-unit");
private List<PlaySession> playSessions;
@PostConstruct
public void run() {
this.entityManager = factory.createEntityManager();
CriteriaQuery<PlaySession> criteria =
this.entityManager.getCriteriaBuilder().createQuery(PlaySession.class);
this.playSessions =
this.entityManager.createQuery(criteria.select(criteria.from(PlaySession.class)))
.getResultList();
this.entityManager.close();
}
....
But it always failed and complained that PlaySession is not an Entity
Is there a way to inject the Named Stateful bean to Singleton? If not, is there any workaround for it?
Thanks