New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[appserver-io/appserver] EntityManager instance gets nulled #881

Closed
wick-ed opened this Issue Jul 22, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@wick-ed
Member

wick-ed commented Jul 22, 2015

Wrapping the Doctrine entity manager does seem to have problems with context switches. In certain situations (not clear which) a second request to a webapp results in the error message:

PHP Fatal error: Call to a member function getConnection() on null in /opt/appserver/src/AppserverIo/Appserver/PersistenceContainer/Doctrine/DoctrineEntityManagerDecorator.php on line 47
@wick-ed

This comment has been minimized.

Show comment
Hide comment
@wick-ed

wick-ed Jul 23, 2015

Member

This seems to be a problem within DI which reaches several levels of stacking.
Example:

A servlet which gets a stateful bean injected:

/**
 * @Route(name="test", urlPattern={"/test.do", "/test.do*"}, initParams={})
 */
class TestServlet extends HttpServlet {

    /**
     * The test processor instance
     *
     * @var \TestProcessor
     * @EnterpriseBean(name="TestProcessor")
     */
    protected $testProcessor;
}

The TestProcessor SFSB:

/**
 * @Stateful
 */
class TestProcessor extends AbstractProcessor {

    /**
     * Another processor instance
     *
     * @var \AnotherProcessor
     * @EnterpriseBean(name="AnotherProcessor")
     */
    protected $anotherProcessor;
}

The other SFSB

/**
 * @Stateful
 */
class AnotherProcessor extends AbstractProcessor {
}

The AbstractProcessor does have a persistence unit injected as such:

    /**
     * The Doctrine EntityManager instance.
     *
     * @var \Doctrine\ORM\EntityManager
     * @PersistenceUnit(unitName="EntityManager")
     */
    protected $entityManager;

This constellation does lead to the described error on the second request, given that all injected objects are in fact injected (e.g. after using them).
The EntityManager instance present in the wrapper the AnotherProcessor class got injected will be null then.
This indicates a DI problem when injecting a complete dependency tree of at least 2 level.

Member

wick-ed commented Jul 23, 2015

This seems to be a problem within DI which reaches several levels of stacking.
Example:

A servlet which gets a stateful bean injected:

/**
 * @Route(name="test", urlPattern={"/test.do", "/test.do*"}, initParams={})
 */
class TestServlet extends HttpServlet {

    /**
     * The test processor instance
     *
     * @var \TestProcessor
     * @EnterpriseBean(name="TestProcessor")
     */
    protected $testProcessor;
}

The TestProcessor SFSB:

/**
 * @Stateful
 */
class TestProcessor extends AbstractProcessor {

    /**
     * Another processor instance
     *
     * @var \AnotherProcessor
     * @EnterpriseBean(name="AnotherProcessor")
     */
    protected $anotherProcessor;
}

The other SFSB

/**
 * @Stateful
 */
class AnotherProcessor extends AbstractProcessor {
}

The AbstractProcessor does have a persistence unit injected as such:

    /**
     * The Doctrine EntityManager instance.
     *
     * @var \Doctrine\ORM\EntityManager
     * @PersistenceUnit(unitName="EntityManager")
     */
    protected $entityManager;

This constellation does lead to the described error on the second request, given that all injected objects are in fact injected (e.g. after using them).
The EntityManager instance present in the wrapper the AnotherProcessor class got injected will be null then.
This indicates a DI problem when injecting a complete dependency tree of at least 2 level.

@wick-ed wick-ed added memory and removed memory labels Jul 24, 2015

@wagnert wagnert self-assigned this Sep 17, 2016

@wagnert wagnert closed this in d7f31d7 Sep 19, 2016

wagnert added a commit that referenced this issue Sep 19, 2016

Merge pull request #1030 from wagnert/master
Closed #881 EntityManager instance gets nulled

AW3i added a commit to AW3i/appserver that referenced this issue Oct 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment