Hey Timothy,

I thought I saw a bug from you about Oracle+D2, so I went back looking for
it :-)

Could you please verify if this behavior is just Oracle-specific or if
mysql/sqlite/pgsql are also affected?

Cheers,

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/


On 4 March 2014 15:24, Timothy Lorens <[email protected]> wrote:

> I was having some issues persisting associated records to our Oracle
> database.  The primary/parent entity was configured in the mapper to use a
> SEQUENCE.   It seems as if the SequenceGenerator was returning an improper
> sequence ID and Doctrine kept throwing an exception that the primary ID
> wasn't set on the associated record (or something to that nature)
>
> After some debugging and SQL logging.  I noticed that the parent ID for
> the associated entities was off by 1.
>
>     public function generate(EntityManager $em, $entity)
>     {
>         if ($this->_maxValue === null || $this->_nextValue ==
> $this->_maxValue) {
>             // Allocate new values
>             $conn = $em->getConnection();
>             $sql  =
> $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);
>
>             $this->_nextValue = (int)$conn->fetchColumn($sql);
>             $this->_maxValue  = $this->_nextValue + $this->_allocationSize;
>         }
>
>         return ++$this->_nextValue;
>     }
>
> I didn't get too involved in figuring out exactly how this function
> worked.  But by incrementing _nextValue prior to returning it seems to have
> solved the problem.
>
> If this isn't a bug with Doctrine 2 working with Oracle, Could someone
> please shed some light the issue of why the returned ID is 1 less than the
> parent ID inserted into the database.
>
> Setting *allocation-size* and *initial-value* didn't seem to change this
> behavior.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "doctrine-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/doctrine-user.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to