Segmentation fault when column have nullable ManyToOne relation #6708

Open
opened 2026-01-22 15:37:21 +01:00 by admin · 5 comments
Owner

Originally created by @Nicc0 on GitHub (May 3, 2021).

I created Product entity using PHP8 attributes.

#[Entity]
#[Table("app_product")]
class ProductEntity {
   
   ...

    #[ManyToOne(targetEntity: CategoryEntity::class, cascade: [ 'persist' ])]
    #[JoinColumn(nullable: true)]
    public ?CategoryEntity $category;
}

The table was generated correctly, allowing nullable value for column category_id
But when I trying to add new one entity by $this->em->persist( $productEntity ) console returns Segmentation fault.
It happens only when $category isn't set. (I mean that value is equal null)

Can anyone help me? I would be grateful!

Edit 1:
I noticed that is not a persist method problem, because the error appears after calling the $this->em->commit() method.

Originally created by @Nicc0 on GitHub (May 3, 2021). I created Product entity using PHP8 attributes. ```php #[Entity] #[Table("app_product")] class ProductEntity { ... #[ManyToOne(targetEntity: CategoryEntity::class, cascade: [ 'persist' ])] #[JoinColumn(nullable: true)] public ?CategoryEntity $category; } ``` The table was generated correctly, allowing nullable value for column `category_id` But when I trying to add new one entity by `$this->em->persist( $productEntity )` console returns `Segmentation fault`. It happens only when $category isn't set. (I mean that value is equal `null`) Can anyone help me? I would be grateful! Edit 1: I noticed that is not a `persist` method problem, because the error appears after calling the `$this->em->commit()` method.
Author
Owner

@Nicc0 commented on GitHub (May 4, 2021):

I found a cause why this problem occurs. During binding parameter category_id to the insert statement the type is set to integer, even then category is set to null. The error Segmentation fault is returned by original PDO object. I changed locally logic of setting types for columns in /Doctrine/ORM/Persisters/Entity/BasicEntityPersister::prepareUpdateData().

I think in this place we should to check $joinColumn have a attribute nullable set to true and the value is null also. If yes, set the $columnTypes of current column to null.

@Nicc0 commented on GitHub (May 4, 2021): I found a cause why this problem occurs. During binding parameter `category_id` to the insert statement the type is set to `integer`, even then category is set to `null`. The error `Segmentation fault` is returned by original PDO object. I changed locally logic of setting types for columns in `/Doctrine/ORM/Persisters/Entity/BasicEntityPersister::prepareUpdateData()`. I think in this place we should to check `$joinColumn` have a attribute nullable set to true and the value is null also. If yes, set the `$columnTypes` of current column to `null`.
Author
Owner

@michaljusiega commented on GitHub (May 4, 2021):

Segmentation fault is always returned from PHP, not third-party library.

@michaljusiega commented on GitHub (May 4, 2021): Segmentation fault is always returned from PHP, not third-party library.
Author
Owner

@Nicc0 commented on GitHub (May 4, 2021):

Can someone link a PullRequest to this issue?

@Nicc0 commented on GitHub (May 4, 2021): Can someone link a [PullRequest](https://github.com/doctrine/orm/pull/8670/files) to this issue?
Author
Owner

@bibich commented on GitHub (May 6, 2021):

Same issue for me.
using https://github.com/api-platform/api-platform

@bibich commented on GitHub (May 6, 2021): Same issue for me. using https://github.com/api-platform/api-platform
Author
Owner

@windigo00 commented on GitHub (Jun 18, 2025):

Hi. I found out it was caused by wrong annotation of related entities. It happened to me when I had JoinColumn on both sides. Try removing it from one side.

@windigo00 commented on GitHub (Jun 18, 2025): Hi. I found out it was caused by wrong annotation of related entities. It happened to me when I had JoinColumn on both sides. Try removing it from one side.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6708