[jboss-user] [JBoss Seam] - Re: servlet in seam application
Basel
do-not-reply at jboss.com
Tue Aug 15 06:21:46 EDT 2006
Injecting an EntityManager into a servlet is not recommended since the former is not thread safe. Here is what I do in my current web application:
| @PersistenceUnit(name = "myPU")
| private EntityManagerFactory factory;
|
| protected void doGet(HttpServletRequest request,
| HttpServletResponse response) throws ServletException,
| IOException{
| try{
| if(factory == null){
| String name = "java:/myEntityManagerFactory";
| factory = (EntityManagerFactory)
| Naming.getInitialContext().lookup(name);
| }
| if(em == null){
| em = factory.createEntityManager();
| }
| }
| }catch(NamingException e){
| err.println("NamingException when trying to get an " +
| "EntityManager: "+e.getMessage());
| e.printStackTrace();
| }
| }
|
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3965218#3965218
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3965218
More information about the jboss-user
mailing list