You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by "Matthias Weßendorf (JIRA)" <ji...@apache.org> on 2011/02/27 17:34:39 UTC

[jira] Created: (OWB-534) Injection of @PersistenceContext does not work with abstract/base classes

Injection of @PersistenceContext does not work with abstract/base classes
-------------------------------------------------------------------------

                 Key: OWB-534
                 URL: https://issues.apache.org/jira/browse/OWB-534
             Project: OpenWebBeans
          Issue Type: Bug
          Components: Injection and Lookup
    Affects Versions: 1.0.0
            Reporter: Matthias Weßendorf
            Assignee: Gurkan Erdogdu
            Priority: Critical


I am using an "AbstractGenericDao" class for all of my DAOs.
In there I use @PersistenceContext(unitName = "myUnit") to inject the EntityManager

The concrete DAO (e.g. EmployeeDao (which extends AbstractGenericDao)) is inject (via @Inject) to a Service IMPL.

Now, when executing some logic on that DAO, where it delegates to the EntityManager (e.g. em.persist(...);) I am getting a NullPointerException, indicating that the EntityManager is NULL 

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (OWB-534) Injection of @PersistenceContext does not work with abstract/base classes

Posted by "Matthias Weßendorf (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OWB-534?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12999987#comment-12999987 ] 

Matthias Weßendorf commented on OWB-534:
----------------------------------------

Stack trace:


Caused by: java.lang.NullPointerException
	at net.wessendorf.enterprise.jpa.dao.AbstractGenericDao.create(AbstractGenericDao.java:16)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.webbeans.intercept.InvocationContextImpl.proceedAroundInvokes(InvocationContextImpl.java:255)
	at org.apache.webbeans.intercept.InvocationContextImpl.proceed(InvocationContextImpl.java:175)
	at org.apache.myfaces.extensions.cdi.jpa.impl.TransactionalInterceptor.invoke(TransactionalInterceptor.java:139)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.webbeans.intercept.InvocationContextImpl.proceedAroundInvokes(InvocationContextImpl.java:237)
	at org.apache.webbeans.intercept.InvocationContextImpl.proceed(InvocationContextImpl.java:175)
	at org.apache.webbeans.intercept.DependentScopedBeanInterceptorHandler.callAroundInvokes(DependentScopedBeanInterceptorHandler.java:86)
	at org.apache.webbeans.intercept.InterceptorHandler.invoke(InterceptorHandler.java:266)
	at org.apache.webbeans.intercept.DependentScopedBeanInterceptorHandler.invoke(DependentScopedBeanInterceptorHandler.java:75)
	at net.wessendorf.enterprise.jpa.dao.EmployeeDaoImpl_$$_javassist_32.create(EmployeeDaoImpl_$$_javassist_32.java)
	at net.wessendorf.enterprise.service.EmployeeServiceImpl.saveEmployee(EmployeeServiceImpl.java:38)
	at net.wessendorf.enterprise.faces.CreateEmployeeController.createEmployee(CreateEmployeeController.java:34)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.webbeans.intercept.InterceptorHandler.invoke(InterceptorHandler.java:287)
	at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.invoke(NormalScopedBeanInterceptorHandler.java:98)
	at net.wessendorf.enterprise.faces.CreateEmployeeController_$$_javassist_31.createEmployee(CreateEmployeeController_$$_javassist_31.java)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
	at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
	at org.apache.myfaces.view.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:83)
	... 42 more

> Injection of @PersistenceContext does not work with abstract/base classes
> -------------------------------------------------------------------------
>
>                 Key: OWB-534
>                 URL: https://issues.apache.org/jira/browse/OWB-534
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Injection and Lookup
>    Affects Versions: 1.0.0
>            Reporter: Matthias Weßendorf
>            Assignee: Gurkan Erdogdu
>            Priority: Critical
>
> I am using an "AbstractGenericDao" class for all of my DAOs.
> In there I use @PersistenceContext(unitName = "myUnit") to inject the EntityManager
> The concrete DAO (e.g. EmployeeDao (which extends AbstractGenericDao)) is inject (via @Inject) to a Service IMPL.
> Now, when executing some logic on that DAO, where it delegates to the EntityManager (e.g. em.persist(...);) I am getting a NullPointerException, indicating that the EntityManager is NULL 

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Resolved: (OWB-534) Injection of @PersistenceContext does not work with abstract/base classes

Posted by "Mark Struberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OWB-534?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mark Struberg resolved OWB-534.
-------------------------------

       Resolution: Duplicate
    Fix Version/s: 1.0.1
                   1.1.0
         Assignee: Mark Struberg  (was: Gurkan Erdogdu)

> Injection of @PersistenceContext does not work with abstract/base classes
> -------------------------------------------------------------------------
>
>                 Key: OWB-534
>                 URL: https://issues.apache.org/jira/browse/OWB-534
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Injection and Lookup
>    Affects Versions: 1.0.0
>            Reporter: Matthias Weßendorf
>            Assignee: Mark Struberg
>            Priority: Critical
>             Fix For: 1.1.0, 1.0.1
>
>         Attachments: OWB-534.zip
>
>
> I am using an "AbstractGenericDao" class for all of my DAOs.
> In there I use @PersistenceContext(unitName = "myUnit") to inject the EntityManager
> The concrete DAO (e.g. EmployeeDao (which extends AbstractGenericDao)) is inject (via @Inject) to a Service IMPL.
> Now, when executing some logic on that DAO, where it delegates to the EntityManager (e.g. em.persist(...);) I am getting a NullPointerException, indicating that the EntityManager is NULL 

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (OWB-534) Injection of @PersistenceContext does not work with abstract/base classes

Posted by "Matthias Weßendorf (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OWB-534?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12999991#comment-12999991 ] 

Matthias Weßendorf commented on OWB-534:
----------------------------------------

Attached is a simple example. It uses my "abstractGenericDao"

unzip the file and run the following command "mvn".
This downloads jetty etc and starts the container on localhost:9090

afterwards point the browser to that URL and use the app to see the OWB bug.

Click the "all" link - or try to create a new employee ==> Both actions fail due to a NPE in the base DAO class.


================== WORK AROUND ============

Now to make it work.... you could change the EmployeeServiceImpl and replace this:

<toReplace>
  @Inject
  private EmployeeDao dao;
  //private SimpleEmployeeDao dao;
</toReplace>

with this:
<replacement>
  @Inject
  private SimpleEmployeeDao dao;
</replacement>


==> This makes it working, but it's not desired to use DAOs like that. 

The goal is to make the @PersistenceContext annotation working via abstract base classes as well (instead of only simple classes)

> Injection of @PersistenceContext does not work with abstract/base classes
> -------------------------------------------------------------------------
>
>                 Key: OWB-534
>                 URL: https://issues.apache.org/jira/browse/OWB-534
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Injection and Lookup
>    Affects Versions: 1.0.0
>            Reporter: Matthias Weßendorf
>            Assignee: Gurkan Erdogdu
>            Priority: Critical
>         Attachments: OWB-534.zip
>
>
> I am using an "AbstractGenericDao" class for all of my DAOs.
> In there I use @PersistenceContext(unitName = "myUnit") to inject the EntityManager
> The concrete DAO (e.g. EmployeeDao (which extends AbstractGenericDao)) is inject (via @Inject) to a Service IMPL.
> Now, when executing some logic on that DAO, where it delegates to the EntityManager (e.g. em.persist(...);) I am getting a NullPointerException, indicating that the EntityManager is NULL 

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Updated: (OWB-534) Injection of @PersistenceContext does not work with abstract/base classes

Posted by "Matthias Weßendorf (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OWB-534?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matthias Weßendorf updated OWB-534:
-----------------------------------

    Attachment: OWB-534.zip

The example application.

Shows the bug (on default)
and has (as described in my comments) an undesired "work around".

> Injection of @PersistenceContext does not work with abstract/base classes
> -------------------------------------------------------------------------
>
>                 Key: OWB-534
>                 URL: https://issues.apache.org/jira/browse/OWB-534
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Injection and Lookup
>    Affects Versions: 1.0.0
>            Reporter: Matthias Weßendorf
>            Assignee: Gurkan Erdogdu
>            Priority: Critical
>         Attachments: OWB-534.zip
>
>
> I am using an "AbstractGenericDao" class for all of my DAOs.
> In there I use @PersistenceContext(unitName = "myUnit") to inject the EntityManager
> The concrete DAO (e.g. EmployeeDao (which extends AbstractGenericDao)) is inject (via @Inject) to a Service IMPL.
> Now, when executing some logic on that DAO, where it delegates to the EntityManager (e.g. em.persist(...);) I am getting a NullPointerException, indicating that the EntityManager is NULL 

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (OWB-534) Injection of @PersistenceContext does not work with abstract/base classes

Posted by "Matthias Weßendorf (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OWB-534?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12999988#comment-12999988 ] 

Matthias Weßendorf commented on OWB-534:
----------------------------------------

Using a simple DAO (all in one class - no abstraction, no inheritance) makes it working!

> Injection of @PersistenceContext does not work with abstract/base classes
> -------------------------------------------------------------------------
>
>                 Key: OWB-534
>                 URL: https://issues.apache.org/jira/browse/OWB-534
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Injection and Lookup
>    Affects Versions: 1.0.0
>            Reporter: Matthias Weßendorf
>            Assignee: Gurkan Erdogdu
>            Priority: Critical
>
> I am using an "AbstractGenericDao" class for all of my DAOs.
> In there I use @PersistenceContext(unitName = "myUnit") to inject the EntityManager
> The concrete DAO (e.g. EmployeeDao (which extends AbstractGenericDao)) is inject (via @Inject) to a Service IMPL.
> Now, when executing some logic on that DAO, where it delegates to the EntityManager (e.g. em.persist(...);) I am getting a NullPointerException, indicating that the EntityManager is NULL 

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira