Hey again.
I Found a solution: It works if I manually inject an EntityManager using the
EntityManagerFactory. I was just under the impression that it was supposed to
do that automatically in a container mannaged environment.
The revised code for the session bean follows:
| package sm.comm.frontend2.beans.sessions;
|
| import javax.ejb.Stateless;
| import javax.persistence.EntityManager;
| import javax.persistence.EntityManagerFactory;
| import javax.persistence.PersistenceContext;
| import javax.persistence.PersistenceUnit;
| import sm.beans.entities.Employee;
| import sm.comm.frontend2.dtos.assemblers.EmployeeAssembler;
| import sm.comm.frontend2.dtos.assemblers.SkillAssembler;
| import sm.comm.frontend2.dtos.DetailEmployeeDTO;
| import sm.comm.frontend2.dtos.SkillDTO;
|
| @Stateless
| public class F2FacadeBean implements F2FacadeRemote {
| @PersistenceUnit
| private EntityManagerFactory em;
|
| public DetailEmployeeDTO EmployeeDTO(int id) {
| Employee emp = em.createEntityManager().find(Employee.class, id);
| return EmployeeAssembler.createDetailEmployeeDTO(emp);
| }
|
| public void persistSkill(SkillDTO skill) {
| System.out.println(skill.getName());
| System.out.println(em.createEntityManager().isOpen());
| em.createEntityManager().persist(SkillAssembler.createSkill(skill));
| }
|
| public String hello() {
| return "Hello World!";
| }
|
| }
|
It contains some debugging code, but the idea should be clear.
I just got brain wave. Am I right in thinking that if I want to directly inject
the EntityManager I should use @PersistenceContext, and if I use
@PersistenceUnit I need to use the factory?
Thanks a lot for the time taken to help out with this
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4185235#4185235
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4185235
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user