doctrine 2 oracle datetime column showing “not a valid month” on insert entity

老子叫甜甜 提交于 2019-12-05 21:57:33

Found that bug here too... it's OracleSessionInit not being called!

But i dunno if it's a missing config part or if it's a bug from doctrine not enabling that by default if you use oci8

edit:

just found it! and i should add that you should add a service in invokers at service_manager pointing to \Doctrine\DBAL\Event\Listeners\OracleSessionInit, so it should be something like this:

'invokables' => array(
    'oracle-session-init' => '\Doctrine\DBAL\Event\Listeners\OracleSessionInit'
),

and this:

'doctrine' => array (
    'driver' => array (
            /** here are your driver settings, such as annotations configs */
    ),
    'eventmanager' => array(
            'orm_default' => array(
                    'subscribers' => array('oracle-session-init')
            )
    )
),

credits to: http://raymondkolbe.com/2012/06/19/doctrineormmodule-and-oraclesessioninit/

Doctrine doesn't call it by default, even with you use the OCI8. In my opnion, it's not a bug because with you can change the NLS params directly in DB, for good, you won't need to call every time you connect the OracleSessionInit. Resulting in 1 query less per session. :)

Another way to solve this it's getting the instances of \Doctrine\ORM\EntityManager and setting the OracleSessionInit, like below. You can also change the default session vars like I did in this example passing an array with the new value to 'NLS_SORT'.

At the Module.php:

public function getServiceConfig() {
    return array(
        'initializers' => array(
            function($instance, $services) {
                if ($instance instanceof \Doctrine\ORM\EntityManager) {
                    $instance->getEventManager()->addEventSubscriber(new \Doctrine\DBAL\Event\Listeners\OracleSessionInit(array(
                        'NLS_SORT' => 'WEST_EUROPEAN_AI',
                    )));
                }
            },
        ),
    );
}

Initializer: A callback that is executed every time the ServiceManager creates a new instance of a class. These are usually used to inject an object into the new class instance if that class implements a particular interface.

More about initializer and Zend\ServiceManager config here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!