java ee - Injection of EJB in EntityListener via CDI fails (JPA 2.1) -
i trying inject @stateless
ejb entitylistner. @prepresist
method of entitylistener invoked, injected ejb resolves null
nullpointerexception thrown.
public class myentitylistener { @inject private myservice myservice; // @stateless ejb @prepersist public void prepersist(myentity entity) { final foo foo = myservice.getfoo(); // !! npe thrown here!! entity.setfoo(foo); } }
previous questions found here on dealing problem, jpa provide cdi jpa 2.1 on not jpa 2.0, using jpa 2.1. else may problem here?
<?xml version="1.0" encoding="utf-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" > <persistence-unit name="my_pu" transaction-type="jta"> <jta-data-source>jdbc/local</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="eclipselink.logging.level" value="all" /> </properties> </persistence-unit> </persistence>
injection of ejb other session beans works fine, both ejb inection (@ejb
) cdi injection (@inject
). fails in entitylistner.
i using glassfish 4.1 eclipselink 2.5.2
related questions: injecting sessionscoped stateful bean in entitylistener
there nothing wrong in code, behaviour caused bug:
the bug fixed in eclipselink 2.6.0. update version solved problem.
Comments
Post a Comment