You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Fay Wang (JIRA)" <ji...@apache.org> on 2008/11/25 00:57:44 UTC

[jira] Created: (OPENJPA-782) Support for collections of embeddables and basic types

Support for collections of embeddables and basic types
------------------------------------------------------

                 Key: OPENJPA-782
                 URL: https://issues.apache.org/jira/browse/OPENJPA-782
             Project: OpenJPA
          Issue Type: Question
            Reporter: Fay Wang
            Assignee: Fay Wang


Regarding jpa 2.0 embeddable, suppose Entity A contains a collection of embeddables.
The collection of embeddable is stored in a separate table. @CollectionTable can be used to specify the table name, etc. If the @CollectionTable is not used, a default table name is used (see spec, p 272 ). 

The embeddable may contain the relation to EntityB in the following scenarios:
(1) If in the embeddable, there is:
      @ManyToOne
       private EnittyB entityB; 
   
       then the relation from EntityA to EntityB is OneToMany, 
       and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
       @ManyToOne
       private EntityA entityA;

(2) If in the embeddable, there is:
      @OneToOne
      private EntityB; 

      then the relation from EntityA to EntityB is OneToMany,
      and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
      @ManyToOne
      private EntityA entityA;

(3) If in the embeddable, there is:
      @OneToOne(mappedBy = "entityB")
       private EntityB
       The relation from EntityA to EnityB is OneToMany,
       and the relation from EntityB to EntityA is ManyToOne:
       @ManyToOne
       private EntityA entityA;       

The relation to EntityB will be stored in the third table (the CollectionTable) so that it can be associated with the embeddable. However, we can not use "mappedBy" in the ManyToOne relation in EntityB. How to have bi-directional relation between EntityA and EntityB in these situations? Is it possible to have a bi-directional relation between these two entities when embeddable is involved as described above?

In scenario (3), an explicit "mappedBy" is specified in the embeddable, so that the bi-directional relation between EntityA and EntityB will be stored in the EntityB table, but then how can we associate EntityB with the embeddable when EntityA is retrieved back as embeddable itself does not have identity?












-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-782) Support for collections of embeddables and basic types

Posted by "Fay Wang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-782?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12681095#action_12681095 ] 

Fay Wang commented on OPENJPA-782:
----------------------------------

Spec 2.5 Embeddable Classes (p 34):

"Since instances of embeddable classes themselves have no persistent identity, the relationship from the referenced entity is to the entity that contains the embeddable instance(s) and not to the embeddable itself."

Spec 10.1.26 ManyToOne Annotation (p. 310):

"The ManyToOne annotation may be used within an embeddable class to specify a relationship from the embeddable class to an entity class."

Spec 10.1.35 OneToOne Annotation (p.323):

"The OneToOne annotation may be used within an embeddable class to specify a relationship from the embeddable class to an entity class. "

Case (1):

EntityA
======
private Collection<EmbedA> embedAs;

EmbedA:
========
@ManyToOne
EntityB entityB;

The values for EntityA, EmbedA, EntityB can be:

EntityA1 - EmbedA1 - EntityB1
                   EmbedA2 - EntityB1
                   EmbedA3 - EntityB2
                   EmbedA4 - EntityB2

The implied relation from EntityA to EntityB is therefore OneToMany. A bi-directional relation between EntityA and EntityB (spec p.40) suggests that the relation from EntityB to EntityA is ManyToOne.

EntityB:
=======
@ManyToOne
private EntityA entityA;


Case(2):

EntityA
======
private Collection<EmbedA> embedAs;

EmbedA:
========
@OneToOne
EntityB entityB;


The values for EntityA, EmbedA, EntityB can be:

EntityA1 - EmbedA1 - EntityB1
                   EmbedA2 - EntityB2
                   EmbedA3 - EntityB3
                   EmbedA4 - EntityB4

The implied relation from EntityA to EntityB is therefore OneToMany. A bi-directional relation between EntityA and EntityB (spec p.40) suggests that the relation from EntityB to EntityA is ManyToOne.

EntityB:
=======
@ManyToOne
private EntityA entityA;


In both cases, EntityA should be the owning side (as it contains EmbedA). In order to specify bi-directional relation, the mappedBy annotation should be specified in EntityB, However, EntityB has ManyToOne relation, which disallows "mappedBy" to be specified. Therefore, IMO, it is not possible to specify bi-directional relation when a collection embeddables is involved. 

> Support for collections of embeddables and basic types
> ------------------------------------------------------
>
>                 Key: OPENJPA-782
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-782
>             Project: OpenJPA
>          Issue Type: Sub-task
>            Reporter: Fay Wang
>            Assignee: Fay Wang
>             Fix For: 2.0.0
>
>         Attachments: openjpa-782-testcase.patch, openjpa-782.patch
>
>
> Regarding jpa 2.0 embeddable, suppose Entity A contains a collection of embeddables.
> The collection of embeddable is stored in a separate table. @CollectionTable can be used to specify the table name, etc. If the @CollectionTable is not used, a default table name is used (see spec, p 272 ). 
> The embeddable may contain the relation to EntityB in the following scenarios:
> (1) If in the embeddable, there is:
>       @ManyToOne
>        private EnittyB entityB; 
>    
>        then the relation from EntityA to EntityB is OneToMany, 
>        and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>        @ManyToOne
>        private EntityA entityA;
> (2) If in the embeddable, there is:
>       @OneToOne
>       private EntityB; 
>       then the relation from EntityA to EntityB is OneToMany,
>       and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>       @ManyToOne
>       private EntityA entityA;
> (3) If in the embeddable, there is:
>       @OneToOne(mappedBy = "entityB")
>        private EntityB
>        The relation from EntityA to EnityB is OneToMany,
>        and the relation from EntityB to EntityA is ManyToOne:
>        @ManyToOne
>        private EntityA entityA;       
> The relation to EntityB will be stored in the third table (the CollectionTable) so that it can be associated with the embeddable. However, we can not use "mappedBy" in the ManyToOne relation in EntityB. How to have bi-directional relation between EntityA and EntityB in these situations? Is it possible to have a bi-directional relation between these two entities when embeddable is involved as described above?
> In scenario (3), an explicit "mappedBy" is specified in the embeddable, so that the bi-directional relation between EntityA and EntityB will be stored in the EntityB table, but then how can we associate EntityB with the embeddable when EntityA is retrieved back as embeddable itself does not have identity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-782) Support for collections of embeddables and basic types

Posted by "Fay Wang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-782?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12650718#action_12650718 ] 

Fay Wang commented on OPENJPA-782:
----------------------------------

Another piece of information: in Spec 2.6: "The embeddable class must be on the owning side of such a relation and the relationship must be mapped by a foreign key mapping". 

> Support for collections of embeddables and basic types
> ------------------------------------------------------
>
>                 Key: OPENJPA-782
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-782
>             Project: OpenJPA
>          Issue Type: Question
>            Reporter: Fay Wang
>            Assignee: Fay Wang
>
> Regarding jpa 2.0 embeddable, suppose Entity A contains a collection of embeddables.
> The collection of embeddable is stored in a separate table. @CollectionTable can be used to specify the table name, etc. If the @CollectionTable is not used, a default table name is used (see spec, p 272 ). 
> The embeddable may contain the relation to EntityB in the following scenarios:
> (1) If in the embeddable, there is:
>       @ManyToOne
>        private EnittyB entityB; 
>    
>        then the relation from EntityA to EntityB is OneToMany, 
>        and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>        @ManyToOne
>        private EntityA entityA;
> (2) If in the embeddable, there is:
>       @OneToOne
>       private EntityB; 
>       then the relation from EntityA to EntityB is OneToMany,
>       and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>       @ManyToOne
>       private EntityA entityA;
> (3) If in the embeddable, there is:
>       @OneToOne(mappedBy = "entityB")
>        private EntityB
>        The relation from EntityA to EnityB is OneToMany,
>        and the relation from EntityB to EntityA is ManyToOne:
>        @ManyToOne
>        private EntityA entityA;       
> The relation to EntityB will be stored in the third table (the CollectionTable) so that it can be associated with the embeddable. However, we can not use "mappedBy" in the ManyToOne relation in EntityB. How to have bi-directional relation between EntityA and EntityB in these situations? Is it possible to have a bi-directional relation between these two entities when embeddable is involved as described above?
> In scenario (3), an explicit "mappedBy" is specified in the embeddable, so that the bi-directional relation between EntityA and EntityB will be stored in the EntityB table, but then how can we associate EntityB with the embeddable when EntityA is retrieved back as embeddable itself does not have identity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-782) Support for collections of embeddables and basic types

Posted by "Fay Wang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-782?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12655734#action_12655734 ] 

Fay Wang commented on OPENJPA-782:
----------------------------------

ElementCollection/CollectionTable annotation and orm support for embeddables and basic types are committed to trunk r-724437 and r-725770. Test case for orm will be checked in later when the orm xml schema is finalized. 


> Support for collections of embeddables and basic types
> ------------------------------------------------------
>
>                 Key: OPENJPA-782
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-782
>             Project: OpenJPA
>          Issue Type: Sub-task
>            Reporter: Fay Wang
>            Assignee: Fay Wang
>         Attachments: openjpa-782-testcase.patch, openjpa-782.patch
>
>
> Regarding jpa 2.0 embeddable, suppose Entity A contains a collection of embeddables.
> The collection of embeddable is stored in a separate table. @CollectionTable can be used to specify the table name, etc. If the @CollectionTable is not used, a default table name is used (see spec, p 272 ). 
> The embeddable may contain the relation to EntityB in the following scenarios:
> (1) If in the embeddable, there is:
>       @ManyToOne
>        private EnittyB entityB; 
>    
>        then the relation from EntityA to EntityB is OneToMany, 
>        and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>        @ManyToOne
>        private EntityA entityA;
> (2) If in the embeddable, there is:
>       @OneToOne
>       private EntityB; 
>       then the relation from EntityA to EntityB is OneToMany,
>       and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>       @ManyToOne
>       private EntityA entityA;
> (3) If in the embeddable, there is:
>       @OneToOne(mappedBy = "entityB")
>        private EntityB
>        The relation from EntityA to EnityB is OneToMany,
>        and the relation from EntityB to EntityA is ManyToOne:
>        @ManyToOne
>        private EntityA entityA;       
> The relation to EntityB will be stored in the third table (the CollectionTable) so that it can be associated with the embeddable. However, we can not use "mappedBy" in the ManyToOne relation in EntityB. How to have bi-directional relation between EntityA and EntityB in these situations? Is it possible to have a bi-directional relation between these two entities when embeddable is involved as described above?
> In scenario (3), an explicit "mappedBy" is specified in the embeddable, so that the bi-directional relation between EntityA and EntityB will be stored in the EntityB table, but then how can we associate EntityB with the embeddable when EntityA is retrieved back as embeddable itself does not have identity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-782) Support for collections of embeddables and basic types

Posted by "Fay Wang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-782?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Fay Wang updated OPENJPA-782:
-----------------------------

    Attachment: openjpa-782-testcase.patch
                openjpa-782.patch

The patch includes:
(1) new JPA2.0 annotations: ElementCollection and CollectionTable. 
(2) fix of JIRA-777 
(3) fix to support the scenario when an entity contains a collection of embeddables, and the embeddable has a nested embeddable in it. Currently, openjpa only allows basic types and toOne relation in an embeddable element.

> Support for collections of embeddables and basic types
> ------------------------------------------------------
>
>                 Key: OPENJPA-782
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-782
>             Project: OpenJPA
>          Issue Type: Sub-task
>            Reporter: Fay Wang
>            Assignee: Fay Wang
>         Attachments: openjpa-782-testcase.patch, openjpa-782.patch
>
>
> Regarding jpa 2.0 embeddable, suppose Entity A contains a collection of embeddables.
> The collection of embeddable is stored in a separate table. @CollectionTable can be used to specify the table name, etc. If the @CollectionTable is not used, a default table name is used (see spec, p 272 ). 
> The embeddable may contain the relation to EntityB in the following scenarios:
> (1) If in the embeddable, there is:
>       @ManyToOne
>        private EnittyB entityB; 
>    
>        then the relation from EntityA to EntityB is OneToMany, 
>        and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>        @ManyToOne
>        private EntityA entityA;
> (2) If in the embeddable, there is:
>       @OneToOne
>       private EntityB; 
>       then the relation from EntityA to EntityB is OneToMany,
>       and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>       @ManyToOne
>       private EntityA entityA;
> (3) If in the embeddable, there is:
>       @OneToOne(mappedBy = "entityB")
>        private EntityB
>        The relation from EntityA to EnityB is OneToMany,
>        and the relation from EntityB to EntityA is ManyToOne:
>        @ManyToOne
>        private EntityA entityA;       
> The relation to EntityB will be stored in the third table (the CollectionTable) so that it can be associated with the embeddable. However, we can not use "mappedBy" in the ManyToOne relation in EntityB. How to have bi-directional relation between EntityA and EntityB in these situations? Is it possible to have a bi-directional relation between these two entities when embeddable is involved as described above?
> In scenario (3), an explicit "mappedBy" is specified in the embeddable, so that the bi-directional relation between EntityA and EntityB will be stored in the EntityB table, but then how can we associate EntityB with the embeddable when EntityA is retrieved back as embeddable itself does not have identity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-782) Support for collections of embeddables and basic types

Posted by "Jeremy Bauer (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-782?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jeremy Bauer updated OPENJPA-782:
---------------------------------

    Issue Type: Sub-task  (was: Question)
        Parent: OPENJPA-800

> Support for collections of embeddables and basic types
> ------------------------------------------------------
>
>                 Key: OPENJPA-782
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-782
>             Project: OpenJPA
>          Issue Type: Sub-task
>            Reporter: Fay Wang
>            Assignee: Fay Wang
>
> Regarding jpa 2.0 embeddable, suppose Entity A contains a collection of embeddables.
> The collection of embeddable is stored in a separate table. @CollectionTable can be used to specify the table name, etc. If the @CollectionTable is not used, a default table name is used (see spec, p 272 ). 
> The embeddable may contain the relation to EntityB in the following scenarios:
> (1) If in the embeddable, there is:
>       @ManyToOne
>        private EnittyB entityB; 
>    
>        then the relation from EntityA to EntityB is OneToMany, 
>        and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>        @ManyToOne
>        private EntityA entityA;
> (2) If in the embeddable, there is:
>       @OneToOne
>       private EntityB; 
>       then the relation from EntityA to EntityB is OneToMany,
>       and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>       @ManyToOne
>       private EntityA entityA;
> (3) If in the embeddable, there is:
>       @OneToOne(mappedBy = "entityB")
>        private EntityB
>        The relation from EntityA to EnityB is OneToMany,
>        and the relation from EntityB to EntityA is ManyToOne:
>        @ManyToOne
>        private EntityA entityA;       
> The relation to EntityB will be stored in the third table (the CollectionTable) so that it can be associated with the embeddable. However, we can not use "mappedBy" in the ManyToOne relation in EntityB. How to have bi-directional relation between EntityA and EntityB in these situations? Is it possible to have a bi-directional relation between these two entities when embeddable is involved as described above?
> In scenario (3), an explicit "mappedBy" is specified in the embeddable, so that the bi-directional relation between EntityA and EntityB will be stored in the EntityB table, but then how can we associate EntityB with the embeddable when EntityA is retrieved back as embeddable itself does not have identity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (OPENJPA-782) Support for collections of embeddables and basic types

Posted by "Fay Wang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-782?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Fay Wang resolved OPENJPA-782.
------------------------------

       Resolution: Fixed
    Fix Version/s: 2.0.0

In this iteration, the following are supported:
1) nested embeddables: spec 2.5 
2) collections of embeddables and basic types: spec 2.2, 2.6
3) relationships within embeddables: spec 2.5, 10.1.22, 10.1.24, 10.1.25, 10.1.34 
4) @CollectionTable annotation and XML (Parser/Serializer): spec 10.1.7
5) @ElementCollection annotation and XML (Parser/Serializer): spec 10.1.11

Incmplete and pending issues:
(1)  2.7.2 
(2) 10.1.35 (OrderBy for embeddable) 
(3)  JIRA-793
(4) processing/serialization for version 1 and version 2 of the ORM/PersistenceUnit XML Schema.

> Support for collections of embeddables and basic types
> ------------------------------------------------------
>
>                 Key: OPENJPA-782
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-782
>             Project: OpenJPA
>          Issue Type: Sub-task
>            Reporter: Fay Wang
>            Assignee: Fay Wang
>             Fix For: 2.0.0
>
>         Attachments: openjpa-782-testcase.patch, openjpa-782.patch
>
>
> Regarding jpa 2.0 embeddable, suppose Entity A contains a collection of embeddables.
> The collection of embeddable is stored in a separate table. @CollectionTable can be used to specify the table name, etc. If the @CollectionTable is not used, a default table name is used (see spec, p 272 ). 
> The embeddable may contain the relation to EntityB in the following scenarios:
> (1) If in the embeddable, there is:
>       @ManyToOne
>        private EnittyB entityB; 
>    
>        then the relation from EntityA to EntityB is OneToMany, 
>        and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>        @ManyToOne
>        private EntityA entityA;
> (2) If in the embeddable, there is:
>       @OneToOne
>       private EntityB; 
>       then the relation from EntityA to EntityB is OneToMany,
>       and the relation from EntityB to EntityA is ManyToOne (Spec 2.5):
>       @ManyToOne
>       private EntityA entityA;
> (3) If in the embeddable, there is:
>       @OneToOne(mappedBy = "entityB")
>        private EntityB
>        The relation from EntityA to EnityB is OneToMany,
>        and the relation from EntityB to EntityA is ManyToOne:
>        @ManyToOne
>        private EntityA entityA;       
> The relation to EntityB will be stored in the third table (the CollectionTable) so that it can be associated with the embeddable. However, we can not use "mappedBy" in the ManyToOne relation in EntityB. How to have bi-directional relation between EntityA and EntityB in these situations? Is it possible to have a bi-directional relation between these two entities when embeddable is involved as described above?
> In scenario (3), an explicit "mappedBy" is specified in the embeddable, so that the bi-directional relation between EntityA and EntityB will be stored in the EntityB table, but then how can we associate EntityB with the embeddable when EntityA is retrieved back as embeddable itself does not have identity?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.