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 (Updated) (JIRA)" <ji...@apache.org> on 2012/02/13 09:20:59 UTC
[jira] [Updated] (OPENJPA-2127) Join table in unidirectional
one-to-many relationship with Map does not follow JPA v2 specification
[ https://issues.apache.org/jira/browse/OPENJPA-2127?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Maria Jurcovicova updated OPENJPA-2127:
---------------------------------------
Description:
According to JPA v2 specification page 50, the joining table name should be composed from entity names (e.g. class names) by default. The table should have two columns.
Table name:
* owner class name
* underscore "_"
* inverse class name.
Name of the column with inverses ids:
* the name of the relationship property or field of the owner
* underscore "_"
* the name of the primary key column in table inverse.
If the annotated property maps data into the map, OpenJPA assumes different database structure.
OpenJPA table name:
* owner class name <- OK
* underscore "_" <- OK
* the name of the relationship property or field of the owner <- WRONG
OpenJPA column with inverses id name:
* "element_id" <- WRONG
Name of the column with owners ids is correct.
Extract from the specification:
"Entity A is mapped to a table named A.
Entity B is mapped to a table named B.
There is a join table that is named A_B (owner name first). This join table has two foreign key
columns. One foreign key column refers to table A and has the same type as the primary key of
table A. The name of this foreign key column is formed as the concatenation of the following:
the name of entity A; "_"; the name of the primary key column in table A. The other foreign
key column refers to table B and has the same type as the primary key of table B and there is a
unique key constraint on it. The name of this foreign key column is formed as the concatenation
of the following: the name of the relationship property or field of entity A; "_"; the name
of the primary key column in table B."
Example entities:
@Entity
public class MapOneToManyOwner {
@Id
private long id;
@OneToMany
@MapKey(name="mapKey")
private Map<String, MapOneToManyInverse> inverses;
}
@Entity
public class MapOneToManyInverse {
@Id
private long id;
private String mapKey;
}
Expected table name: MapOneToManyOwner_MapOneToManyInverse
OpenJPA table name: MapOneToManyOwner_inverses
Expected column name: inverses_id
OpenJPA column name: element_id
DB structure that works with JPA:
CREATE TABLE MapOneToManyOwner_inverses (
MapOneToManyOwner_id INT NOT NULL,
element_id INT NOT NULL,
UNIQUE (element_id)
);
Note: this happens only if the annotated property is a map. If it is a collection, join table structure is different.
was:
According to JPA v2 specification page 50, the joining table name should be composed from entity names (e.g. class names) by default. The table should have two columns.
Table name:
* owner class name
* underscore "_"
* inverse class name.
Name of the column with inverses ids:
* the name of the relationship property or field of the owner
* underscore "_"
* the name of the primary key column in table inverse.
If the annotated property maps data into the map, OpenJPA assumes different database structure.
OpenJPA table name:
* owner class name <- OK
* underscore "_" <- OK
* the name of the relationship property or field of the owner <- WRONG
OpenJPA column with inverses id name:
* "element_id" <- WRONG
Note: this happens only with map. The default table structure with collection is different.
> Join table in unidirectional one-to-many relationship with Map does not follow JPA v2 specification
> ---------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-2127
> URL: https://issues.apache.org/jira/browse/OPENJPA-2127
> Project: OpenJPA
> Issue Type: Bug
> Components: jdbc, jpa
> Affects Versions: 2.1.1
> Reporter: Maria Jurcovicova
>
> According to JPA v2 specification page 50, the joining table name should be composed from entity names (e.g. class names) by default. The table should have two columns.
> Table name:
> * owner class name
> * underscore "_"
> * inverse class name.
> Name of the column with inverses ids:
> * the name of the relationship property or field of the owner
> * underscore "_"
> * the name of the primary key column in table inverse.
> If the annotated property maps data into the map, OpenJPA assumes different database structure.
> OpenJPA table name:
> * owner class name <- OK
> * underscore "_" <- OK
> * the name of the relationship property or field of the owner <- WRONG
> OpenJPA column with inverses id name:
> * "element_id" <- WRONG
> Name of the column with owners ids is correct.
> Extract from the specification:
> "Entity A is mapped to a table named A.
> Entity B is mapped to a table named B.
> There is a join table that is named A_B (owner name first). This join table has two foreign key
> columns. One foreign key column refers to table A and has the same type as the primary key of
> table A. The name of this foreign key column is formed as the concatenation of the following:
> the name of entity A; "_"; the name of the primary key column in table A. The other foreign
> key column refers to table B and has the same type as the primary key of table B and there is a
> unique key constraint on it. The name of this foreign key column is formed as the concatenation
> of the following: the name of the relationship property or field of entity A; "_"; the name
> of the primary key column in table B."
> Example entities:
> @Entity
> public class MapOneToManyOwner {
> @Id
> private long id;
> @OneToMany
> @MapKey(name="mapKey")
> private Map<String, MapOneToManyInverse> inverses;
> }
> @Entity
> public class MapOneToManyInverse {
> @Id
> private long id;
> private String mapKey;
> }
> Expected table name: MapOneToManyOwner_MapOneToManyInverse
> OpenJPA table name: MapOneToManyOwner_inverses
> Expected column name: inverses_id
> OpenJPA column name: element_id
> DB structure that works with JPA:
> CREATE TABLE MapOneToManyOwner_inverses (
> MapOneToManyOwner_id INT NOT NULL,
> element_id INT NOT NULL,
> UNIQUE (element_id)
> );
> Note: this happens only if the annotated property is a map. If it is a collection, join table structure is different.
--
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