java ee - EntityManager not injected into MDB (although other resources are) -
in following code, queues injected correctly, entity manager not. not experienced javaee , @ loss why doesn't work. hints appreciated!
i use openejb application container. using code below, queue
, connectionfactory
injected correctly; however, entitymanager
null
. far know, 1 can use @persistencecontext
in managed entity (i.e., bean) it. or need define in ejb-jar.xml file?
here code looks like:
the mdb:
public class serverbean implements messagelistener { @resource private connectionfactory factory; @resource(name = "queue") private queue queue; @persistencecontext private entitymanager em; //methods... }
ejb-jar.xml:
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" metadata-complete="true"> <enterprise-beans> <message-driven> <ejb-name>serverbean</ejb-name> <ejb-class>foo.serverbean</ejb-class> <messaging-type>javax.jms.messagelistener</messaging-type> <activation-config> <activation-config-property> <activation-config-property-name>destination</activation-config-property-name> <activation-config-property-value>serverbean</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>destinationtype</activation-config-property-name> <activation-config-property-value>javax.jms.queue</activation-config-property-value> </activation-config-property> </activation-config> <resource-ref> <res-ref-name>java:comp/env/foo.serverbean/factory</res-ref-name> <res-type>javax.jms.connectionfactory</res-type> <injection-target> <injection-target-class>foo.serverbean</injection-target-class> <injection-target-name>factory</injection-target-name> </injection-target> </resource-ref> <resource-env-ref> <resource-env-ref-name>java:comp/env/queue</resource-env-ref-name> <resource-env-ref-type>javax.jms.queue</resource-env-ref-type> <mapped-name>queue</mapped-name> <injection-target> <injection-target-class>foo.serverbean</injection-target-class> <injection-target-name>queue</injection-target-name> </injection-target> </resource-env-ref> </message-driven> </enterprise-beans> </ejb-jar>
persitence.xml:
<?xml version="1.0" encoding="utf-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="foounit" transaction-type="jta"> <provider>org.hibernate.ejb.hibernatepersistence</provider> <jta-data-source>foo_ds</jta-data-source> <class>foo.model.bar</class> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="hibernate.connection.driver_class" value="org.h2.driver" /> <property name="hibernate.connection.url" value="jdbc:h2:/tmp/database/dst;auto_server=true;mvcc=true" /> <property name="hibernate.dialect" value="org.hibernate.dialect.h2dialect" /> <property name="hibernate.hbm2ddl.auto" value="create-drop" /> <property name="javax.persistence.validation.mode" value="none"/> <property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.classicquerytranslatorfactory" /> </properties> </persistence-unit> </persistence>
Comments
Post a Comment