Versioned entities in a class table inheritance cannot be persisted because of thrown LengthException #6905

Open
opened 2026-01-22 15:41:04 +01:00 by admin · 0 comments
Owner

Originally created by @kryptychon on GitHub (Jan 13, 2022).

BC Break Report

Q A
BC Break I guess yes
Version 2.11.0

Summary

Persisting versioned entities in a class table inheritance scenario fails with LengthException. Migration notes do not mention any changes regarding versioned entities.

Previous behavior

Persisting such entities worked fine in 2.10.3 (previous version I used).

Current behavior

Persisting versioned entities in a class table inheritance scenario fails with LengthException. I think this is related to commit e369cb6e73 which introduced generated/virtual properties and requires version column to provide a value before initially flushing the newly created entity in JoinedSubclassPersister.php.

Simply moving assignDefaultVersionAndUpsertableValues() AFTER the insertion of the joined subclass fixes the issue.

I'll try to provide a PR asap.

How to reproduce

Try persisting a versioned entity in a class table inheritance scenario.

Example

/**
 * @ORM\Entity()
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorTable({
 *     "user_group_contract" = "UserGroupContract"
 * })
 */
abstract class SubjectOfElection {

    /**
     * @ORM\Column(type="guid")
     * @ORM\Id()
     */
    private string $id;

}

/**
 * @ORM\Entity()
 */
class UserGroupContract extends SubjectOfElection {
    /**
     * @ORM\Column(type="integer")
     * @ORM\Version()
     */
    private int $version;
}
Originally created by @kryptychon on GitHub (Jan 13, 2022). ### BC Break Report | Q | A |------------ | ------ | BC Break | I guess yes | Version | 2.11.0 #### Summary Persisting versioned entities in a class table inheritance scenario fails with `LengthException`. Migration notes do not mention any changes regarding versioned entities. #### Previous behavior Persisting such entities worked fine in `2.10.3` (previous version I used). #### Current behavior Persisting versioned entities in a class table inheritance scenario fails with `LengthException`. I think this is related to commit e369cb6e73f7f6cd2f8fb6c977e1566ed273ca59 which introduced generated/virtual properties and requires `version` column to provide a value before initially flushing the newly created entity in `JoinedSubclassPersister.php`. Simply moving `assignDefaultVersionAndUpsertableValues()` AFTER the insertion of the joined subclass fixes the issue. I'll try to provide a PR asap. #### How to reproduce Try persisting a versioned entity in a class table inheritance scenario. #### Example ~~~php /** * @ORM\Entity() * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="type", type="string") * @ORM\DiscriminatorTable({ * "user_group_contract" = "UserGroupContract" * }) */ abstract class SubjectOfElection { /** * @ORM\Column(type="guid") * @ORM\Id() */ private string $id; } /** * @ORM\Entity() */ class UserGroupContract extends SubjectOfElection { /** * @ORM\Column(type="integer") * @ORM\Version() */ private int $version; } ~~~
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6905