How to inject to class to become persistent?
Hi All Developers,
I have a problem about the Injection in web application using j2EE. I'am creating a customers entry.. The error is [ EntityManager can not be injected into a web application that uses multithread model because EntityManager is not thread safe. ]
but i put in customers_entry.java servlets
@EJB
private CustomersRemote customersBean;
.......
but here
protected void processRequest(HttpServletResponse response,
HttpServletRequest request)
{
........
try{
customersBean.create(1, request.getParameter("name")
, request.getParameter("address")
, request.getParameter("telno")
, request.getParameter("mobileno"));
}catch(Exception ex){
throw new EJBException(ex.toString());
}
}
.......
Kindly explain why it is occur like this...
Best Regards,
CJ
[918 byte] By [
CJ_125a] at [2007-11-27 5:40:26]

# 1
Hi CJ,
Where exactly are you getting this message from? Is it a warning from the verifier tool or is your
application deployment being rejected?
Technically, injecting an EntityManager into a servlet is allowed. However, it's dangerous because
a servlet instance is inherently multi-threaded while an EntityManager is intended to be used by
only one thread at a time.That can result in errors at runtime.
This issue is not unique to EntityManagers. It's true of any object that does not support concurrent
access that a developer puts in instance state of a servlet. E.g., a stateful session bean.
--ken
ksaksa at 2007-7-12 15:16:48 >

# 2
Hi Ken,
Yap but the problems is i'm directly injecting the entity bean to the web, if i'am going to verify Project in netbeans the error always shows.
EntityManager can not be injected into a web application that uses multithread model because EntityManager is not thread safe. Please refer to EJB 3.0 Persistence API Specification section #5.2 for further information.
For [ SavingAccounts-war ]
Found a persistence unit by name [ SavingAccounts ] injected into [ com.savingsaccount.session.CustomersBean ].
Do you have an idea to solve this? or entity suggestion for code?
Thanks ken.