[ https://issues.apache.org/jira/browse/OPENJPA-113?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12478779 ]
Kevin Sutter commented on OPENJPA-113: -------------------------------------- FYI, we have also encountered this problem with annotations. If you re-specify the table designation in the @Column annotation, OpenJPA thinks there's another field named "<class><id>". This only seems to be a problem with @Id fields that also have an @Column annotation: @Entity @Table(name="ITEM") public class ItemJPA { public int itemId; public String itemName; public java.math.BigDecimal itemPrice; public String itemData; @Id @Column(name="I_ID", table="ITEM") @GeneratedValue(strategy=GenerationType.AUTO) public int getItemId() { return itemId; } : } In this case, OpenJPA created another attribute named ItemJPA_I_ID, and of course, the SQL statements generated were not correct: prepstmnt 1986688618 UPDATE ITEM SET I_PRICE = ? WHERE I_ID = ? AND ItemJPA_I_ID = ? [params=(BigDecimal) 500, (int) 1, (int) 1] An easy workaround is to just remove this redundant specification in the @Column annotation. Kevin > when you specify columm table="empbean" in the xml file entity id or basic > type when empbean is the default table name, the mapping tool generates extra > foreign key field (eg.EmpBean_empid) in the table produced. > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > Key: OPENJPA-113 > URL: https://issues.apache.org/jira/browse/OPENJPA-113 > Project: OpenJPA > Issue Type: Bug > Environment: windows xp, openjpa_097_incubating > Reporter: George Hongell > Priority: Minor > Fix For: 0.9.7 > > > when you specify columm table="empbean" in the xml file entity id or basic > type when empbean is the default table name, the mapping tool generates extra > foreign key field (eg.EmpBean_empid) in the table produced. This causes a > SQL0203 (A reference to column name is ambiguous) on empid when you try to > persist this entity. > <entity name="EmpBean" class="EmpBean" access="FIELD"> > <attributes> > <id name="empid"> > <column name="empid" nullable="false" > column-definition="integer" /> > </id> > <basic name="name" fetch="EAGER"> > <column length="40"/> > </basic> > <basic name="salary" fetch="EAGER" > > <column name="salary" table="empbean"/> > </basic> > <basic name="bonus" fetch="EAGER"> > </basic> > <basic name="isManager" fetch="EAGER"> > </basic> > <basic name="execLevel" fetch="EAGER"> > </basic> > <basic name="hireDate" fetch="EAGER"> > </basic> > <basic name="hireTime" fetch="EAGER"> > </basic> > <basic name="hireTimestamp" fetch="EAGER"> > </basic> > <many-to-one name="dept" > target-entity="com.ibm.ws.query.entities.xml.DeptBean" fetch="EAGER"> > </many-to-one> > <one-to-many name="manages" target-entity="DeptBean" fetch="LAZY" > mapped-by="mgr"> > <cascade><cascade-remove/></cascade> > </one-to-many> > > <one-to-one name="home" target-entity="AddressBean" fetch="EAGER"> > </one-to-one> > > <one-to-one name="work" target-entity="AddressBean" fetch="EAGER"> > </one-to-one> > > <many-to-many name="tasks" target-entity="TaskBean" fetch="LAZY" > mapped-by="emps"> > </many-to-many> > </attributes> > </entity> > 4787 mdd TRACE [main] openjpa.jdbc.SQL - <t 1094861122, conn 1274432502> > executing stmnt 1129857880 CREATE TABLE EmpBean (empid INTEGER NOT NULL, > bonus DOUBLE, execLevel INTEGER, hireDate DATE, hireTime TIME, hireTimestamp > TIMESTAMP, isManager SMALLINT, name VARCHAR(40), EmpBean_empid INTEGER, > salary DOUBLE, dept_deptno INTEGER, home_street VARCHAR(40), work_street > VARCHAR(40), PRIMARY KEY (empid)) -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.