I got following exception on IBM Websphere Application server 8.5 when I tried to deploy my application on server.
I’m using WS 8.5, EJB 3.1, Java EE 6 in my application.
[11/1/12 11:06:47:208 PKT] 0000005d annotations E CWWAM0003E: An exception occurred while validating an annotation: com.ibm.wsspi.amm.validate.ValidationException: CWWAM2302E: The class com.xxx.yyy.services.UsersServiceBean is annotated with an invalid @PersistenceContext declaration; no name is specified.
com.ibm.wsspi.amm.validate.ValidationException: CWWAM2302E: The class com.xxx.yyy.services.UsersServiceBean is annotated with an invalid @PersistenceContext declaration; no name is specified.
at com.ibm.ws.amm.validate.persistence.PersistenceContextValidator.validateClassAnnotation(PersistenceContextValidator.java:86)
Below is my Java code.
@PersistenceContext(unitName="myUnit")
@Stateless(name="UsersService")
public class UsersServiceBean implements UsersService {...}
In short, when declaring
@PersistenceUniton a class, you must add aname="..."that you can use to look up theEntityManagerFactorywithnew InitialContext("java:..."). Alternatively, you can declare an@PersistenceUnit(...) EntityManagerFactory emf;field in your class and omit the name.All ref annotations are basically the same as
@Resource. Per the commons annotations specification:The last sentence is relevant, and it makes sense: using
@PersistenceUnit(and all other@Resource-like annotations) has two effects:java:compnamespace using its name. If you declare the annotation on a field or method, the default name isjava:comp/env/com.example.ClassName/targetName.If you declare the annotation on a class, then (1) there’s no injection, and (2) there’s no default name so there’s no way to bind into
java:comp/env. In that case, the annotation declaration would be pointless, so it’s an error.