OpenJPA
  1. OpenJPA
  2. OPENJPA-113

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.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.1, 1.1.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      windows xp, openjpa_097_incubating

      Description

      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))

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        272d 16h 6m 1 Michael Dick 24/Oct/07 19:10
        Resolved Resolved Closed Closed
        867d 22m 1 Donald Woods 09/Mar/10 18:32
        Donald Woods made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Michael Dick made changes -
        Fix Version/s 1.1.0 [ 12312344 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.0.1 [ 12312687 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Patrick Linskey made changes -
        Fix Version/s 0.9.8 [ 12312446 ]
        Michael Dick made changes -
        Assignee Michael Dick [ mikedd ]
        Michael Dick made changes -
        Fix Version/s 0.9.7 [ 12312340 ]
        Fix Version/s 0.9.8 [ 12312446 ]
        Hide
        Kevin Sutter added a comment -

        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

        Show
        Kevin Sutter added a comment - 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
        Patrick Linskey made changes -
        Priority Major [ 3 ] Minor [ 4 ]
        Patrick Linskey made changes -
        Field Original Value New Value
        Fix Version/s 0.9.7 [ 12312340 ]
        George Hongell created issue -

          People

          • Assignee:
            Michael Dick
            Reporter:
            George Hongell
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development