I am working on a project where we are using Zend 2 and doctrine 2 with oracle database. my entity has a field create_date with datetime type. my entity are 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 saving this entity with
$user = new Personnel();
$user->set_login_name('Admin');
$this->getEntityManager()->persist($user);
$this->getEntityManager()->flush();
but showng an error
SQLSTATE[HY000]: General error: 1843 OCIStmtExecute: ORA-01843: not a valid month (ext\pdo_oci\oci_statement.c:148)
Please Help me.
advanced thx
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
:More about initializer and Zend\ServiceManager config here.
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:
and this:
credits to: http://raymondkolbe.com/2012/06/19/doctrineormmodule-and-oraclesessioninit/