You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Maria Jurcovicova (Created) (JIRA)" <ji...@apache.org> on 2012/02/10 14:56:59 UTC

[jira] [Created] (OPENJPA-2126) Default join table column name in many-to-many relationship does not follow JPA v2 specification

Default join table column name in many-to-many relationship does not follow JPA v2 specification
------------------------------------------------------------------------------------------------

                 Key: OPENJPA-2126
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2126
             Project: OpenJPA
          Issue Type: Bug
          Components: jdbc, jpa
    Affects Versions: 2.1.1
            Reporter: Maria Jurcovicova


According to JPA v2 specification page 48, the joining table should have two columns. One column should have foreign key to owners table and the other should have foreign key to the inverse table. 

The name of the column referencing the owner should be:
* the name of the relationship property or field of inverse entity ; 
* underscore "_";
* the name of the primary key column in owner table. 

OpenJPA assumes that the name of  the column referencing the owner is:
* owner entity name ; 
* underscore "_";
* the name of the primary key column in owner table. 

The name of the column referencing the inverse is correct.

Example entities:
@Entity
@Table(name="tblMtmOwner")
public class MtmOwner {
  @Id
  private long id;
  private String name;
  @ManyToMany
  private Collection<MtmInverse> inverses = new ArrayList<MtmInverse>();
}
 
@Entity
public class MtmInverse{
  @Id
  private long id;
  @ManyToMany(mappedBy="inverses")
  @MapKey(name="name")
  private Map<String, MtmOwner> owners = new HashMap<String, MtmOwner>();
}

Expected column name: owners_id
OpenJPA column name: mtmowner_id 


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OPENJPA-2126) Default join table column name in many-to-many relationship does not follow JPA v2 specification

Posted by "Maria Jurcovicova (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13214640#comment-13214640 ] 

Maria Jurcovicova commented on OPENJPA-2126:
--------------------------------------------

I would expect that naming generation rules when the @ManyToMany is being represented by a Map should be the same as when it is represented by a Collection. 

I changed this issue priority to Minor, since it does not really need it to be fixed.
                
> Default join table column name in many-to-many relationship does not follow JPA v2 specification
> ------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2126
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2126
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc, jpa
>    Affects Versions: 2.1.1
>            Reporter: Maria Jurcovicova
>            Priority: Minor
>
> According to JPA v2 specification page 48, the joining table should have two columns. One column should have foreign key to owners table and the other should have foreign key to the inverse table. 
> The name of the column referencing the owner should be:
> * the name of the relationship property or field of inverse entity ; 
> * underscore "_";
> * the name of the primary key column in owner table. 
> OpenJPA assumes that the name of  the column referencing the owner is:
> * owner entity name ; 
> * underscore "_";
> * the name of the primary key column in owner table. 
> The name of the column referencing the inverse is correct.
> Example entities:
> @Entity
> @Table(name="tblMtmOwner")
> public class MtmOwner {
>   @Id
>   private long id;
>   private String name;
>   @ManyToMany
>   private Collection<MtmInverse> inverses = new ArrayList<MtmInverse>();
> }
>  
> @Entity
> public class MtmInverse{
>   @Id
>   private long id;
>   @ManyToMany(mappedBy="inverses")
>   @MapKey(name="name")
>   private Map<String, MtmOwner> owners = new HashMap<String, MtmOwner>();
> }
> Expected column name: owners_id
> OpenJPA column name: mtmowner_id 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OPENJPA-2126) Default join table column name in many-to-many relationship does not follow JPA v2 specification

Posted by "Kevin Sutter (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13213724#comment-13213724 ] 

Kevin Sutter commented on OPENJPA-2126:
---------------------------------------

My guess is that the introduction of the Map type and @MapKey annotation is confusing this name resolution.  If you change the type of owners to a standard Collection, I bet the name generation is correct.  Looking through the spec, it's not clear on the naming expectations when using a Map.  The only reference is this sentence in section 2.7.2:

"When the value type of the map is an entity, a join table is used to map the map for a many-to-many
relationship.."

But, I can't find any naming generation rules when the @ManyToMany is being represented by a Map.  I've also searched other references to find general guidelines without any luck.  Since you always have the ability to override the defaults via the @JoinTable annotation, I'm not sure we would entertain changes in this area.  Unless we can determine a more definitive explanation of the naming requirements.

Thanks,  Kevin
                
> Default join table column name in many-to-many relationship does not follow JPA v2 specification
> ------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2126
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2126
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc, jpa
>    Affects Versions: 2.1.1
>            Reporter: Maria Jurcovicova
>
> According to JPA v2 specification page 48, the joining table should have two columns. One column should have foreign key to owners table and the other should have foreign key to the inverse table. 
> The name of the column referencing the owner should be:
> * the name of the relationship property or field of inverse entity ; 
> * underscore "_";
> * the name of the primary key column in owner table. 
> OpenJPA assumes that the name of  the column referencing the owner is:
> * owner entity name ; 
> * underscore "_";
> * the name of the primary key column in owner table. 
> The name of the column referencing the inverse is correct.
> Example entities:
> @Entity
> @Table(name="tblMtmOwner")
> public class MtmOwner {
>   @Id
>   private long id;
>   private String name;
>   @ManyToMany
>   private Collection<MtmInverse> inverses = new ArrayList<MtmInverse>();
> }
>  
> @Entity
> public class MtmInverse{
>   @Id
>   private long id;
>   @ManyToMany(mappedBy="inverses")
>   @MapKey(name="name")
>   private Map<String, MtmOwner> owners = new HashMap<String, MtmOwner>();
> }
> Expected column name: owners_id
> OpenJPA column name: mtmowner_id 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (OPENJPA-2126) Default join table column name in many-to-many relationship does not follow JPA v2 specification

Posted by "Maria Jurcovicova (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-2126?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13214643#comment-13214643 ] 

Maria Jurcovicova commented on OPENJPA-2126:
--------------------------------------------

Since OPENJPA-2127 was very similar to this issue and has been closed as a duplicate, I will the relevant pieces from it here.

1.) The unidirectional one-to-many relationship with Map has similar join table name issue.
2.) Join table in an unidirectional one-to-many relationship with Map uses "element_id" as the name of the column with inverses. 




                
> Default join table column name in many-to-many relationship does not follow JPA v2 specification
> ------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2126
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2126
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc, jpa
>    Affects Versions: 2.1.1
>            Reporter: Maria Jurcovicova
>            Priority: Minor
>
> According to JPA v2 specification page 48, the joining table should have two columns. One column should have foreign key to owners table and the other should have foreign key to the inverse table. 
> The name of the column referencing the owner should be:
> * the name of the relationship property or field of inverse entity ; 
> * underscore "_";
> * the name of the primary key column in owner table. 
> OpenJPA assumes that the name of  the column referencing the owner is:
> * owner entity name ; 
> * underscore "_";
> * the name of the primary key column in owner table. 
> The name of the column referencing the inverse is correct.
> Example entities:
> @Entity
> @Table(name="tblMtmOwner")
> public class MtmOwner {
>   @Id
>   private long id;
>   private String name;
>   @ManyToMany
>   private Collection<MtmInverse> inverses = new ArrayList<MtmInverse>();
> }
>  
> @Entity
> public class MtmInverse{
>   @Id
>   private long id;
>   @ManyToMany(mappedBy="inverses")
>   @MapKey(name="name")
>   private Map<String, MtmOwner> owners = new HashMap<String, MtmOwner>();
> }
> Expected column name: owners_id
> OpenJPA column name: mtmowner_id 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (OPENJPA-2126) Default join table column name in many-to-many relationship does not follow JPA v2 specification

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

Maria Jurcovicova updated OPENJPA-2126:
---------------------------------------

    Priority: Minor  (was: Major)
    
> Default join table column name in many-to-many relationship does not follow JPA v2 specification
> ------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2126
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2126
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jdbc, jpa
>    Affects Versions: 2.1.1
>            Reporter: Maria Jurcovicova
>            Priority: Minor
>
> According to JPA v2 specification page 48, the joining table should have two columns. One column should have foreign key to owners table and the other should have foreign key to the inverse table. 
> The name of the column referencing the owner should be:
> * the name of the relationship property or field of inverse entity ; 
> * underscore "_";
> * the name of the primary key column in owner table. 
> OpenJPA assumes that the name of  the column referencing the owner is:
> * owner entity name ; 
> * underscore "_";
> * the name of the primary key column in owner table. 
> The name of the column referencing the inverse is correct.
> Example entities:
> @Entity
> @Table(name="tblMtmOwner")
> public class MtmOwner {
>   @Id
>   private long id;
>   private String name;
>   @ManyToMany
>   private Collection<MtmInverse> inverses = new ArrayList<MtmInverse>();
> }
>  
> @Entity
> public class MtmInverse{
>   @Id
>   private long id;
>   @ManyToMany(mappedBy="inverses")
>   @MapKey(name="name")
>   private Map<String, MtmOwner> owners = new HashMap<String, MtmOwner>();
> }
> Expected column name: owners_id
> OpenJPA column name: mtmowner_id 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira