Hi, everybody!
I'm trying to perform EM dependency injection in servlet using JBoss 5 Beta 1
and get the following deployment exception:
ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController]
| Error installing to Start: name=jboss.web.deployment:war=/simple-web
state=Create mode=Manual requiredState=Installed
|
| java.lang.RuntimeException:
@PersistenceContext(name='env/Test/em',unitName='test-jpa') on EJB:
| simple-web.war failed to inject on field javax.persistence.EntityManager
Test.em
|
| Unable to find persistence unit: test-jpa for deployment: simple-web.war
| at org.jboss.injection.PcEncInjector.inject(PcEncInjector.java:75)
| at
org.jboss.web.tomcat.tc6.TomcatInjectionContainer.populateEnc(TomcatInjectionContainer.java:206)
| ...
NOTE: When there were some errors in persistence.xml (now fixed), server
reported them explicitly. Though, how can it be that server is "Unable to find
persistence unit: test-jpa", but is able to find errors in it?
And a warning:
WARN [org.hibernate.ejb.Ejb3Configuration] Persistence provider caller does
not implements the EJB3 spec correctly.
PersistenceUnitInfo.getNewTempClassLoader() is null.
When invoking servlet I get the following response:
exception
|
| javax.servlet.ServletException: Error instantiating servlet class Test
|
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:86)
|
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
|
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:212)
| ...
|
| root cause
|
| java.lang.RuntimeException: Unable to inject jndi dependency: env/Test/em
into field interface javax.persistence.EntityManager
| org.jboss.injection.JndiFieldInjector.lookup(JndiFieldInjector.java:85)
| org.jboss.injection.JndiFieldInjector.inject(JndiFieldInjector.java:99)
| ...
|
| root cause
|
| javax.naming.NameNotFoundException: Test not bound
| org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
| org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
| org.jnp.server.NamingServer.getObject(NamingServer.java:543)
| org.jnp.server.NamingServer.lookup(NamingServer.java:267)
| org.jnp.server.NamingServer.lookup(NamingServer.java:270)
Here is my servlet code:
public class Test ... {
|
| @PersistenceContext(unitName="test-jpa")
| EntityManager em;
|
| protected void doGet(...) {
|
| Mytable mytable = em.find(Mytable.class, new Integer(5));
| response.getOutputStream().print(mytable.getName());
| }
| }
Here is persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
|
| <persistence version="1.0" ... >
| <persistence-unit name="test-jpa" transaction-type="RESOURCE_LOCAL">
| <jta-data-source>java:/MySqlDS</jta-data-source>
| <class>Mytable</class>
| <properties>
| <property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLInnoDBDialect" />
| </properties>
| </persistence-unit>
| </persistence>
WAR structure:
simple-web.war
| /META-INF
| manifest.mf
| /WEB-INF
| /classes
| Test.java (servlet)
| Mytable.java (entity)
| web.xml
| persistence.xml
AFAIK, JBoss 5 is supposed to support dependency injection in servlets. So
what's wrong?
Any help would be pleased. Thanks in advance.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4031401#4031401
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4031401
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user