Hi,

I am a newbie in OJB and an now trying the OJB using the ODMG API. I run the
tutorials on the OJB website successfully. But when I am trying one of my
own project, I was stuck in two problems,

1)

for the query string, if I use "select p from Project where companyCode = $1
and billingCode= $2;" everything is fine. But if I am trying to use the
alias for the object, replacing the above query with "select p from Project
p where p.companyCode = $1 and p.billingCode= $2;" there will be exception
thownn,

line 1: unexpected token: p
java.lang.NullPointerException
.....

The following is the code.
 public Project locateProjectByCodes(String company_code, String
billing_code)
 {
      String oqlQuery = "select p from Project where companyCode = $1 and
billingCode= $2";
      Database db = odmg.getDatabase(null); // the current DB
      Transaction tx = null;
      Project oneInstance=null;
       try
       {
    // 3. open transaction
    tx = odmg.newTransaction();
    tx.begin();

    // 4. acquire write lock on new object
   OQLQuery query = odmg.newOQLQuery();
   try
   {
   query.create(oqlQuery);
   System.err.println("finished creating query");
   }
   catch(QueryInvalidException e)
   {
    System.err.println("query problem!");
   }
   query.bind(company_code);
   query.bind(billing_code);
   DList result = (DList) query.execute();
   java.util.Iterator iter = result.iterator();

    // 5. commit transaction
    tx.commit();

    //6. loop the result collection
   if (iter.hasNext())
   {
    oneInstance = (Project) result.get(0);
   }

   logger.warn("locateProjectByCodes: "+oneInstance.getCompanyCode());
   }
   catch( Exception e )
   {
    System.err.println(e.toString());
    tx.abort();
    e.printStackTrace();
  //  e.printStackTrace(logger);
    // Code omitted for tutorial brevity....
   }
   return null;
 }

2) how to query two or more tables? Like the above example, say I have a
table Employee (to simplify the question, we assume it is 1:1 relationship
between these two tables, each employee works on one project)and I want to
get the project information a specified employee works on. With sql, I would
write as "select p.* from Project p, Employee e where
p.ProjectId=e.ProjectId and e.EmployeeName='me'", but how to do this with
ODMG query? I read all the tutorials and more than one examples on internet,
but all of them only query one table each time... In fact, when I tried to
write the OQL, like the above example, the exception reported my second
table name as unexpected token.

Thank you and I am waiting in such eagerness for your help.

Best,
Jack




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to