I'm migrating a big application to CDI with JPA. Before I can change all code, I need to know if following pattern will work. This will allow me to migrate the application partially.
My Managed Bean:
@Named
@Stateless
public class LanguageBoundary implements Serializable {
@Inject
LanguageService languageService;
@Inject
CrudService crudService;
public LanguageEntity findById(Long id) {
return crudService.find(LanguageEntity.class, id);
}
...
Can I use in any other class:
// Methods: DAO - Used by original deprecated parent wrapper class
public LanguageEntity findByIdImpl(Id id) {
LanguageBoundary lb = new LanguageBoundary();
return lb.findById(id.getValue());
}
Thanks for the advise.
To do something like this, you need to get a reference to the object. You can do this using CDI. In CDI 1.1 you can get the CDI utility class. In CDI 1.0 you can get a reference to the bean manager using JNDI to do the equivalent. Look at this code for reference: https://github.com/apache/deltaspike/blob/master/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/provider/BeanProvider.java#L98
I'm curious why you're using @Named
. Are you planning to reference the EJB directly in your UI?