Question

I have an existing Oracle DB with 2 tables corresponding to the classes below. In the DB, there already exists a FK b/w AllCodes and AllCodesHistory,, such that ALLCODES column in AllCodesHistory contains the primary key from AllCodes.

However, when I execute the code below,

[code]
PersistenceManager pm = JdoPersistenceManager.getPersistenceManagerFacotry().getPersistenceManager();
        Object[] o = null;
        Transaction tx = pm.currentTransaction();
        try
        {
            tx.begin();

            System.out.println("Quering....");
            int objectId = 1234;
            q = pm.newQuery("SELECT  FROM AllCodesHistoryJdoImpl where allcodes == " + objectId);
            obj = (List)q.execute();
            System.out.println(obj);
            //System.out.println("Detaching....done");
            tx.commit();
        }
        finally
        {
            if (tx.isActive())
            {
                tx.rollback();
            }
            pm.close();
        }
[/code]

I get the following exception:

[code]
Exception in thread "main" javax.jdo.JDOUserException: Variable allcodes is unbound and cannot be determined
    at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:549)
    at org.datanucleus.api.jdo.JDOQuery.execute(JDOQuery.java:230)
    at test.Test.main(Test.java:38)
[/code]

Any ideas why I get this error? The class definition and mappings are given at the end.

On using the schemaTool from Data nucleus (& redirecting the output to a file) I see that DN does not acknowledge the fact that the FK is already created and mapped to the PK of ALLCODES, rather it tries to create its own column and FK.

ALTER TABLE ALLCODESHISTORY ADD ALLCODES_OBJECTID_OID NUMBER (38) NULL;
ALTER TABLE ALLCODESHISTORY ADD CONSTRAINT ALLCODESHISTORY_FK1 FOREIGN KEY (ALLCODES_OBJECTID_OID) REFERENCES ALLCODES (OBJECTID) INITIALLY DEFERRED ;

Can this be avoided? Thanks in Advance.

[code]
public class AllCodesJdoImpl {
  public int objectId;
  public String code;

   public AllCodesJdoImpl() {

  }

    public void setMasterCode(String value) throws appException {
        this.masterCode = value;
    }


    public String getCode() throws appException {   
        return this.masterCode;
    }



    public int getObjectId() throws appException {
        // TODO Auto-generated method stub
        return objectId;
    }
}


public class AllCodesHistoryJdoImpl implements AllCodesHistory {


      //
      public String oldValue;
      public int objectId;
      public AllCodesJdoImpl allCodes;

    public AllCodesHistoryJdoImpl() {

    }


    public String getOldValue() throws appException {

        return null;
    }


    public void setOldValue(String value) throws appException {
                      return oldValue;

    }



    public AllCodes getAllCodes() throws appException {

        return allCodes;
    }


    public void setAllCodes(AllCodes value) throws appException {

        allCodes = (AllCodesJdoImpl)value;

    }


 public int getObjectId() throws appException {
                // TODO Auto-generated method stub
                return objectId;
        }


}

The corresponding mapping is as below:
        <class name="AllCodesJdoImpl" table="ALLCODES">
            <field name="code" >
            <column name="CODE" length="35" jdbc-type="VARCHAR" />
            </field>
            <field name="objectId" primary-key="true">
            <column name="OBJECTID" length="38" jdbc-type="INTEGER" />
            </field>
        </class>

        <class name="AllCodesHistoryJdoImpl" table="ALLCODESHISTORY">
            <field name="oldValue" >
            <column name="OLDVALUE" length="255" jdbc-type="VARCHAR" />
            </field>
            <field name="allCodes" >
                <element column="ALLCODES"/>            
            </field>
            <field name="objectId" primary-key="true">
            <column name="OBJECTID" length="38" jdbc-type="INTEGER" />
            </field>
        </class> 

[/code]
Was it helpful?

Solution

You misspelled the field name. Java is case sensitive

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top