You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "George Hongell (JIRA)" <ji...@apache.org> on 2007/04/05 02:41:32 UTC
[jira] Created: (OPENJPA-201) Mapping Tool ignores the @JoinColumn
annotation in a @ManyToOne mapping if the table argument is used
Mapping Tool ignores the @JoinColumn annotation in a @ManyToOne mapping if the table argument is used
-----------------------------------------------------------------------------------------------------
Key: OPENJPA-201
URL: https://issues.apache.org/jira/browse/OPENJPA-201
Project: OpenJPA
Issue Type: Bug
Environment: 0.9.7-incubating-SNAPSHOT
Reporter: George Hongell
@Entity
@Table(name="CxWine")
public class Wine {
@Id
private Integer wineid;
...
@ManyToOne()
@JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
//ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
//ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
//ignored @JoinColumn(name="NEW_WINERY_WINERYID", table="cxWINERY")
//ok @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="wineryid")
//ok @JoinColumn(name="NEW_WINERY_WINERYID")
private Winery winery;
...
}
generates
2744 cxwineTour TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 98698722> executing stmnt 1325027066 CREATE TABLE CxWine (wineid INTEGER NOT NULL, cost SMALLINT, description VARCHAR(254), minimumHoldYears INTEGER, rating SMALLINT, stockCount INTEGER, type VARCHAR(20), version INTEGER, alcoholPercent DOUBLE, ava VARCHAR(40), bottler VARCHAR(40), brandName VARCHAR(40), labelWineClass VARCHAR(20), labelWineColor VARCHAR(20), estateBottled SMALLINT, hasSulfites SMALLINT, labelid INTEGER, mlContents INTEGER, qualityDesignation VARCHAR(40), vineyardName VARCHAR(40), vintage TIMESTAMP, wineName VARCHAR(40), winery_wineryid INTEGER, PRIMARY KEY (wineid))
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (OPENJPA-201) Mapping Tool ignores the
@JoinColumn annotation in a @ManyToOne mapping if the table argument is
used
Posted by "Abe White (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12487565 ]
Abe White commented on OPENJPA-201:
-----------------------------------
The primary table for what entity? The primary table for the entity shown in your example is clearly "CxWine", but the JoinColumn references a table "cxWINERY". That table doesn't appear anywhere else in the example code. So if it's not the entity's table and it's not a secondary table, then it's not a valid mapping.
If you mean it's the primary table of the related entity, then that is not supported by vanilla JPA. The JPA spec does not support one-sided relations based on an inverse foreign key. You'd have to make the relation a two-sided relation and use "mappedBy" on the side that doesn't own the foreign key.
OpenJPA does actually support one-sided inverse-key relations, however. We can go over its support in OpenJPA, but first I'd like confirmation that that's the intent. It doesn't seem likely that each Winery record contains a foreign key to a single Wine record, so maybe I'm on the wrong track.
> Mapping Tool ignores the @JoinColumn annotation in a @ManyToOne mapping if the table argument is used
> -----------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-201
> URL: https://issues.apache.org/jira/browse/OPENJPA-201
> Project: OpenJPA
> Issue Type: Bug
> Environment: 0.9.7-incubating-SNAPSHOT
> Reporter: George Hongell
> Priority: Minor
>
> @Entity
> @Table(name="CxWine")
> public class Wine {
> @Id
> private Integer wineid;
> ...
> @ManyToOne()
> @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", table="cxWINERY")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="wineryid")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID")
> private Winery winery;
> ...
> }
> generates
> 2744 cxwineTour TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 98698722> executing stmnt 1325027066 CREATE TABLE CxWine (wineid INTEGER NOT NULL, cost SMALLINT, description VARCHAR(254), minimumHoldYears INTEGER, rating SMALLINT, stockCount INTEGER, type VARCHAR(20), version INTEGER, alcoholPercent DOUBLE, ava VARCHAR(40), bottler VARCHAR(40), brandName VARCHAR(40), labelWineClass VARCHAR(20), labelWineColor VARCHAR(20), estateBottled SMALLINT, hasSulfites SMALLINT, labelid INTEGER, mlContents INTEGER, qualityDesignation VARCHAR(40), vineyardName VARCHAR(40), vintage TIMESTAMP, wineName VARCHAR(40), winery_wineryid INTEGER, PRIMARY KEY (wineid))
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (OPENJPA-201) Mapping Tool ignores the @JoinColumn
annotation in a @ManyToOne mapping if the table argument is used
Posted by "George Hongell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-201?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
George Hongell updated OPENJPA-201:
-----------------------------------
Attachment: Winery.java
Wine.java
I am attaching the Wine and Winery files. There is a bilateral 1-M relationship between Winery and Wine. Winery maps to 2 tables.
The foreign key is in the Wine table, I thought the table referred to in @JoinColumn was the referenced table for the relationship but now I think I was specifying the wrong table and it should be the primary table owning the relationship.
However when I try using cxWine as the table, @JoinColumn(name="NEW_WINERY_WINERYID", table="cxWINE")
I get both the default and the new foreign key columns.
What am I doing wrong now?
3345 cxwineTour TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 781725336> executing stmnt 1330401100 CREATE TABLE CxWine (wineid INTEGER NOT NULL, cost SMALLINT, description VARCHAR(254), minimumHoldYears INTEGER, rating SMALLINT, stockCount INTEGER, type VARCHAR(20), version INTEGER, alcoholPercent DOUBLE, ava VARCHAR(40), bottler VARCHAR(40), brandName VARCHAR(40), labelWineClass VARCHAR(20), labelWineColor VARCHAR(20), estateBottled SMALLINT, hasSulfites SMALLINT, labelid INTEGER, mlContents INTEGER, qualityDesignation VARCHAR(40), vineyardName VARCHAR(40), vintage TIMESTAMP, wineName VARCHAR(40), winesProduced_wineid INTEGER, NEW_WINERY_WINERYID INTEGER, PRIMARY KEY (wineid))
when I don't specify the table, @JoinColumn(name="NEW_WINERY_WINERYID")
I get
3325 cxwineTour TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 1569086854> executing stmnt 2042263994 CREATE TABLE CxWine (wineid INTEGER NOT NULL, cost SMALLINT, description VARCHAR(254), minimumHoldYears INTEGER, rating SMALLINT, stockCount INTEGER, type VARCHAR(20), version INTEGER, alcoholPercent DOUBLE, ava VARCHAR(40), bottler VARCHAR(40), brandName VARCHAR(40), labelWineClass VARCHAR(20), labelWineColor VARCHAR(20), estateBottled SMALLINT, hasSulfites SMALLINT, labelid INTEGER, mlContents INTEGER, qualityDesignation VARCHAR(40), vineyardName VARCHAR(40), vintage TIMESTAMP, wineName VARCHAR(40), NEW_WINERY_WINERYID INTEGER, PRIMARY KEY (wineid))
in Winery
@Entity
@Table(name="CxWinery")
public class Winery {
...
@OneToMany(mappedBy="winery")
@LRS
private Collection<Wine> winesProduced;
in Wine
@Entity
@Table(name="CxWine")
public class Wine {
...
@ManyToOne()
@Unique
// gfh fails @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
// gfh fails @JoinColumn(name="NEW_WINERY_WINERYID", table="cxWINERY")
// @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="wineryid")
// @JoinColumn(name="NEW_WINERY_WINERYID")
private Winery winery;
> Mapping Tool ignores the @JoinColumn annotation in a @ManyToOne mapping if the table argument is used
> -----------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-201
> URL: https://issues.apache.org/jira/browse/OPENJPA-201
> Project: OpenJPA
> Issue Type: Bug
> Environment: 0.9.7-incubating-SNAPSHOT
> Reporter: George Hongell
> Priority: Minor
> Attachments: Wine.java, Winery.java
>
>
> @Entity
> @Table(name="CxWine")
> public class Wine {
> @Id
> private Integer wineid;
> ...
> @ManyToOne()
> @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", table="cxWINERY")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="wineryid")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID")
> private Winery winery;
> ...
> }
> generates
> 2744 cxwineTour TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 98698722> executing stmnt 1325027066 CREATE TABLE CxWine (wineid INTEGER NOT NULL, cost SMALLINT, description VARCHAR(254), minimumHoldYears INTEGER, rating SMALLINT, stockCount INTEGER, type VARCHAR(20), version INTEGER, alcoholPercent DOUBLE, ava VARCHAR(40), bottler VARCHAR(40), brandName VARCHAR(40), labelWineClass VARCHAR(20), labelWineColor VARCHAR(20), estateBottled SMALLINT, hasSulfites SMALLINT, labelid INTEGER, mlContents INTEGER, qualityDesignation VARCHAR(40), vineyardName VARCHAR(40), vintage TIMESTAMP, wineName VARCHAR(40), winery_wineryid INTEGER, PRIMARY KEY (wineid))
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (OPENJPA-201) Mapping Tool ignores the
@JoinColumn annotation in a @ManyToOne mapping if the table argument is
used
Posted by "George Hongell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12487361 ]
George Hongell commented on OPENJPA-201:
----------------------------------------
In this case, the named table is the primary table for the entity and defined with a @Table(name="cxWinery") annotation. There is no SecondaryTable defined.
> Mapping Tool ignores the @JoinColumn annotation in a @ManyToOne mapping if the table argument is used
> -----------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-201
> URL: https://issues.apache.org/jira/browse/OPENJPA-201
> Project: OpenJPA
> Issue Type: Bug
> Environment: 0.9.7-incubating-SNAPSHOT
> Reporter: George Hongell
> Priority: Minor
>
> @Entity
> @Table(name="CxWine")
> public class Wine {
> @Id
> private Integer wineid;
> ...
> @ManyToOne()
> @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", table="cxWINERY")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="wineryid")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID")
> private Winery winery;
> ...
> }
> generates
> 2744 cxwineTour TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 98698722> executing stmnt 1325027066 CREATE TABLE CxWine (wineid INTEGER NOT NULL, cost SMALLINT, description VARCHAR(254), minimumHoldYears INTEGER, rating SMALLINT, stockCount INTEGER, type VARCHAR(20), version INTEGER, alcoholPercent DOUBLE, ava VARCHAR(40), bottler VARCHAR(40), brandName VARCHAR(40), labelWineClass VARCHAR(20), labelWineColor VARCHAR(20), estateBottled SMALLINT, hasSulfites SMALLINT, labelid INTEGER, mlContents INTEGER, qualityDesignation VARCHAR(40), vineyardName VARCHAR(40), vintage TIMESTAMP, wineName VARCHAR(40), winery_wineryid INTEGER, PRIMARY KEY (wineid))
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (OPENJPA-201) Mapping Tool ignores the
@JoinColumn annotation in a @ManyToOne mapping if the table argument is
used
Posted by "Abe White (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12487321 ]
Abe White commented on OPENJPA-201:
-----------------------------------
Is the named table defined as a SecondaryTable anywhere? How is OpenJPA supposed to know what to do with it? (This would still be a bug either way, but I'm curious whether it's a "need better mapping validation" bug or a "not functioning correctly" bug.)
> Mapping Tool ignores the @JoinColumn annotation in a @ManyToOne mapping if the table argument is used
> -----------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-201
> URL: https://issues.apache.org/jira/browse/OPENJPA-201
> Project: OpenJPA
> Issue Type: Bug
> Environment: 0.9.7-incubating-SNAPSHOT
> Reporter: George Hongell
> Priority: Minor
>
> @Entity
> @Table(name="CxWine")
> public class Wine {
> @Id
> private Integer wineid;
> ...
> @ManyToOne()
> @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", table="cxWINERY")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="wineryid")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID")
> private Winery winery;
> ...
> }
> generates
> 2744 cxwineTour TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 98698722> executing stmnt 1325027066 CREATE TABLE CxWine (wineid INTEGER NOT NULL, cost SMALLINT, description VARCHAR(254), minimumHoldYears INTEGER, rating SMALLINT, stockCount INTEGER, type VARCHAR(20), version INTEGER, alcoholPercent DOUBLE, ava VARCHAR(40), bottler VARCHAR(40), brandName VARCHAR(40), labelWineClass VARCHAR(20), labelWineColor VARCHAR(20), estateBottled SMALLINT, hasSulfites SMALLINT, labelid INTEGER, mlContents INTEGER, qualityDesignation VARCHAR(40), vineyardName VARCHAR(40), vintage TIMESTAMP, wineName VARCHAR(40), winery_wineryid INTEGER, PRIMARY KEY (wineid))
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (OPENJPA-201) Mapping Tool ignores the @JoinColumn
annotation in a @ManyToOne mapping if the table argument is used
Posted by "George Hongell (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-201?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
George Hongell updated OPENJPA-201:
-----------------------------------
Priority: Minor (was: Major)
> Mapping Tool ignores the @JoinColumn annotation in a @ManyToOne mapping if the table argument is used
> -----------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-201
> URL: https://issues.apache.org/jira/browse/OPENJPA-201
> Project: OpenJPA
> Issue Type: Bug
> Environment: 0.9.7-incubating-SNAPSHOT
> Reporter: George Hongell
> Priority: Minor
>
> @Entity
> @Table(name="CxWine")
> public class Wine {
> @Id
> private Integer wineid;
> ...
> @ManyToOne()
> @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", table="cxWINERY")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="wineryid")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID")
> private Winery winery;
> ...
> }
> generates
> 2744 cxwineTour TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 98698722> executing stmnt 1325027066 CREATE TABLE CxWine (wineid INTEGER NOT NULL, cost SMALLINT, description VARCHAR(254), minimumHoldYears INTEGER, rating SMALLINT, stockCount INTEGER, type VARCHAR(20), version INTEGER, alcoholPercent DOUBLE, ava VARCHAR(40), bottler VARCHAR(40), brandName VARCHAR(40), labelWineClass VARCHAR(20), labelWineColor VARCHAR(20), estateBottled SMALLINT, hasSulfites SMALLINT, labelid INTEGER, mlContents INTEGER, qualityDesignation VARCHAR(40), vineyardName VARCHAR(40), vintage TIMESTAMP, wineName VARCHAR(40), winery_wineryid INTEGER, PRIMARY KEY (wineid))
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (OPENJPA-201) Mapping Tool ignores the
@JoinColumn annotation in a @ManyToOne mapping if the table argument is
used
Posted by "Abe White (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/OPENJPA-201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12487816 ]
Abe White commented on OPENJPA-201:
-----------------------------------
I'm sorry, but I don't understand what you're trying to accomplish. You say that Winery maps to two tables, but I don't see any SecondaryTable defined for it. You give the results of various annotations, but I don't know what the actual schema looks like or what relations you want mapped to what columns.
> Mapping Tool ignores the @JoinColumn annotation in a @ManyToOne mapping if the table argument is used
> -----------------------------------------------------------------------------------------------------
>
> Key: OPENJPA-201
> URL: https://issues.apache.org/jira/browse/OPENJPA-201
> Project: OpenJPA
> Issue Type: Bug
> Environment: 0.9.7-incubating-SNAPSHOT
> Reporter: George Hongell
> Priority: Minor
> Attachments: Wine.java, Winery.java
>
>
> @Entity
> @Table(name="CxWine")
> public class Wine {
> @Id
> private Integer wineid;
> ...
> @ManyToOne()
> @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="WINERYID", table="cxWinery")
> //ignored @JoinColumn(name="NEW_WINERY_WINERYID", table="cxWINERY")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID", referencedColumnName="wineryid")
> //ok @JoinColumn(name="NEW_WINERY_WINERYID")
> private Winery winery;
> ...
> }
> generates
> 2744 cxwineTour TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 98698722> executing stmnt 1325027066 CREATE TABLE CxWine (wineid INTEGER NOT NULL, cost SMALLINT, description VARCHAR(254), minimumHoldYears INTEGER, rating SMALLINT, stockCount INTEGER, type VARCHAR(20), version INTEGER, alcoholPercent DOUBLE, ava VARCHAR(40), bottler VARCHAR(40), brandName VARCHAR(40), labelWineClass VARCHAR(20), labelWineColor VARCHAR(20), estateBottled SMALLINT, hasSulfites SMALLINT, labelid INTEGER, mlContents INTEGER, qualityDesignation VARCHAR(40), vineyardName VARCHAR(40), vintage TIMESTAMP, wineName VARCHAR(40), winery_wineryid INTEGER, PRIMARY KEY (wineid))
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.