Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: 2.3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      We should add an IdGenerator that facilitates the DB Vendors UUID()/GUID() generation facilities.

      Although these IdGenerators take more space compared to other Generators there are use-cases which can be only solved with this kind of Id Generator.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Well @GeneratedValue Only works with @Id as I said. But there are low level APIs that you can look up in the UuidGenerator Strategy to use for something like this.

        Show
        Benjamin Eberlei added a comment - Well @GeneratedValue Only works with @Id as I said. But there are low level APIs that you can look up in the UuidGenerator Strategy to use for something like this.
        Hide
        Menno Holtkamp added a comment -

        Well it is an ID generator. So it has to be with @Id.

        it is available, just take a look at the code.

        Mmm, now I am confused, I think we are mis-communicating.

        Maybe using less text and more descriptive examples:

        • is it possible to use Database GUID functionality
          • without using the @Id annotations, to generate values for Entity properties that are not a primary key?
          • note that this Entity unique reference would exist next to a property that does have the @Id annotation

        Attempt 1:

        /**
         * The Order ID used at database level, which does NOT have any meaning within our domain, solely at database level
         *
         * @var integer
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="IDENTITY")
         * @ORM\SequenceGenerator(sequenceName="orders_id_seq")
         */
        protected $_id;
        
        /**
         * The Order reference used at domain level, which DOES have meaning in our domain
         * Typically used to report in emails, printed on Invoices, etc
         *
         * @var string
         * @ORM\Column(name="order_identifier", type="guid")
         */
        protected $_orderIdentifier;
        

        Attempt 2:

        /**
         * The Order ID used at database level, which does NOT have meaning within our domain, solely at database level
         *
         * @var integer
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="IDENTITY")
         * @ORM\SequenceGenerator(sequenceName="orders_id_seq")
         */
        protected $_id;
        
        /**
         * The Order reference used at domain level, which DOES have meaning in our domain
         * Typically used to report in emails, printed on Invoices, etc
         *
         * @var string
         * @ORM\Column(name="order_identifier", type="string", unique=true)
         * @ORM\GeneratedValue(strategy="UUID")
         */
        protected $_orderIdentifier;
        

        Based on Benjamin's first answer I guess that this is not possible. Point is, the second answer indicates that it is possible . What is it?

        Also note that in Attempt 2, the @GeneratedValue annotation on the second property interferes with the ID generation of the Entity defined at the first property. This is probably to realize composite keys, but can result in unexpected behavior since it replaces the way the primary key is generated?

        Show
        Menno Holtkamp added a comment - Well it is an ID generator. So it has to be with @Id. it is available, just take a look at the code. Mmm, now I am confused, I think we are mis-communicating. Maybe using less text and more descriptive examples: is it possible to use Database GUID functionality without using the @Id annotations, to generate values for Entity properties that are not a primary key? note that this Entity unique reference would exist next to a property that does have the @Id annotation Attempt 1: /** * The Order ID used at database level, which does NOT have any meaning within our domain, solely at database level * * @var integer * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\SequenceGenerator(sequenceName="orders_id_seq") */ protected $_id; /** * The Order reference used at domain level, which DOES have meaning in our domain * Typically used to report in emails, printed on Invoices, etc * * @var string * @ORM\Column(name="order_identifier", type="guid") */ protected $_orderIdentifier; Attempt 2: /** * The Order ID used at database level, which does NOT have meaning within our domain, solely at database level * * @var integer * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\SequenceGenerator(sequenceName="orders_id_seq") */ protected $_id; /** * The Order reference used at domain level, which DOES have meaning in our domain * Typically used to report in emails, printed on Invoices, etc * * @var string * @ORM\Column(name="order_identifier", type="string", unique=true) * @ORM\GeneratedValue(strategy="UUID") */ protected $_orderIdentifier; Based on Benjamin's first answer I guess that this is not possible. Point is, the second answer indicates that it is possible . What is it? Also note that in Attempt 2, the @GeneratedValue annotation on the second property interferes with the ID generation of the Entity defined at the first property. This is probably to realize composite keys, but can result in unexpected behavior since it replaces the way the primary key is generated?
        Hide
        Benjamin Eberlei added a comment -

        it is available, just take a look at the code.

        Show
        Benjamin Eberlei added a comment - it is available, just take a look at the code.
        Hide
        Menno Holtkamp added a comment -

        Well, yes, that was my question and that is now answered, thanks.

        It would be nice though to have UUID generation functionality available for non-database specific IDs as well. For instance for:

        • user account activation tokens
        • payment references
        • invoice reference, etc.

        This is now something that has to be implemented at the applciation level. But since we have these generators available, why not re-use it. By adding a @Id annotation, it becomes part of a composite key, which is not the purpose. Maybe I'll dive into the code and see whether this is possible.

        Show
        Menno Holtkamp added a comment - Well, yes, that was my question and that is now answered, thanks. It would be nice though to have UUID generation functionality available for non-database specific IDs as well. For instance for: user account activation tokens payment references invoice reference, etc. This is now something that has to be implemented at the applciation level. But since we have these generators available, why not re-use it. By adding a @Id annotation, it becomes part of a composite key, which is not the purpose. Maybe I'll dive into the code and see whether this is possible.
        Hide
        Benjamin Eberlei added a comment -

        Well it is an ID generator. So it has to be with @Id.

        Show
        Benjamin Eberlei added a comment - Well it is an ID generator. So it has to be with @Id.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Benjamin Eberlei
          • Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: