I've got an entity with the following dcm.xml definition:
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
<entity name="Conversation" table="Conversations">
<!-- ID's -->
<id name="_id" column="ID" type="text">
<generator strategy="AUTO" />
</id>
<!-- Fields -->
<field name="_subject" column="Subject" type="string" />
<!-- Associations -->
<one-to-many field="_conversationMembers" mapped-by="_conversation" target-entity="ConversationMember">
<cascade><cascade-persist /></cascade>
</one-to-many>
</entity>
</doctrine-mapping>
The ID of this entity is an MSSQL 08 Uniqueidentifier.
Now I generate a new Object an flush it into the db.
$conversation = new Conversation();
$em = $dbHandler->getEntityManager();
$conversation->setSubject($subject);
$em->persist($conversation);
$em->flush();
Now I found this Post telling me that after I flushed the entitiy the ID should be set: Get the last insert id with doctrine 2?
If I try this suggestion and add
$conversation->getId();
the ID is still 0.
I can't flush other entities wich are in relation with this because on every insert, doctrine tries to insert the value 0 as Uniqueidentifier in the specified Foreign Key Column.
This, of course, ends up in a error message of sql server.
Does anybody know if i'm doing something wrong ?
Or is there another way to determ the new generated ID ?
I know about some problems working with sql-server and Doctrine2.
Could it hang there, that doctrine just can't work with this constelation ?