DDC-2826: Add support for mapping collections of embeddable objects #3530

Open
opened 2026-01-22 14:21:38 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Nov 28, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user songoko20000:

In Hibernate we can do something like this:

    @Entity
    public class User {
       [...]
       public String getLastname() { ...}

       @ElementCollection
       @CollectionTable(name="Addresses", joinColumns=@JoinColumn(name="user_id"))
       @AttributeOverrides({
          @AttributeOverride(name="street1", column=@Column(name="fld_street"))
       })
       public Set<Address> getAddresses() { ... } 
    }

    @Embeddable
    public class Address {
       public String getStreet1() {...}
       [...]
    }

Basically a collection of value objects is mapped to a new table. Currently Doctrine2 is on its way to support value objects

However, this implementation won't support mapping a collection of objects to a new table and the only way to circumvent this issue is to treat the address an an entity and use an one-to-many unidirectional relationship through a many-to-many join table

Originally created by @doctrinebot on GitHub (Nov 28, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user songoko20000: In [Hibernate](https://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/collections.html#collections-ofvalues) we can do something like this: ``` @Entity public class User { [...] public String getLastname() { ...} @ElementCollection @CollectionTable(name="Addresses", joinColumns=@JoinColumn(name="user_id")) @AttributeOverrides({ @AttributeOverride(name="street1", column=@Column(name="fld_street")) }) public Set<Address> getAddresses() { ... } } @Embeddable public class Address { public String getStreet1() {...} [...] } ``` Basically a collection of value objects is mapped to a new table. Currently Doctrine2 is on its way to [support value objects](https://github.com/doctrine/doctrine2/pull/835) However, this implementation won't support mapping a collection of objects to a new table and the only way to circumvent this issue is to treat the address an an entity and use an [one-to-many unidirectional relationship through a many-to-many join table](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-many-unidirectional-with-join-table)
admin added the New Feature label 2026-01-22 14:21:38 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 8, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-835] was closed:
https://github.com/doctrine/doctrine2/pull/835

@doctrinebot commented on GitHub (Feb 8, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-835] was closed: https://github.com/doctrine/doctrine2/pull/835
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3530