Doctrine 2 Oracle datetime column showing "invalid month" on insert object

I am working on a project where we are using Zend 2 and Doctrine 2 with an oracle database. my entity has a create_date field with type datetime. my essence is below

class Personnel
{

/**
 * @ORM\Column(type="string",unique=true, nullable=false)
 */
protected $login_name;
/**
 * @ORM\Column(type="datetime")
 */
protected $create_date;
public function __construct()
{
    $this->create_date = new \DateTime("now");
}

 public function get_login_name()
{
    return $this->login_name;
}

public function set_login_name($login_name)
{
    $this->login_name = $login_name;
}

      

}

and im saves this object with

$user = new Personnel();
$user->set_login_name('Admin');
$this->getEntityManager()->persist($user);
$this->getEntityManager()->flush();

      

but showing error

    SQLSTATE [HY000]: General error: 1843 OCIStmtExecute: ORA-01843: not a valid month
     (ext \ pdo_oci \ oci_statement.c: 148)

Please help me.

advanced thanks

+3


source to share


2 answers


Found that there is an error here too ... OracleSessionInit is not being called!

But I don't know if this is the missing piece of the config, or if it is a bug from doctrine that doesn't allow it by default if you are using oci8

edit:

just found! and I must add that you should add the service to invokers in the service_manager pointing to \ Doctrine \ DBAL \ Event \ Listeners \ OracleSessionInit, so there 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: http://raymondkolbe.com/2012/06/19/doctrineormmodule-and-oraclesessioninit/

+3


source


Doctrine does not call it by default, even if you are using OCI8. In my opinion, this is not an error, because you can change the NLS parameters directly in the DB, forever, you will not need to call every time you connect OracleSessionInit. Result in 1 less request per session. :)

Another way to solve this problem is to get instances of \ Doctrine \ ORM \ EntityManager and configure OracleSessionInit as shown below. You can also change the default initial session of the session, as in this example, by passing an array with the new value to "NLS_SORT".

On 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 invoked every time the ServiceManager creates a new instance of the class. They are usually used to inject an object into an instance of a new class if that class implements a specific interface.

Learn more about the Zend \ ServiceManager initializer and configuration here .

0


source







All Articles