QueryByCriteria is not working

"Kamal Bhatt" <[email protected]>
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Hi,
I have a postgres database and I have successfully added a record.

I am trying to query the record. To do this, I have the following code:

    public static Product findByTemplate(Product template)
    {
        PersistenceBroker broker = null;

        Product result = null;
        try
        {
            System.out.println("template: " + template.getId());
            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
            QueryByCriteria query = new QueryByCriteria(template);
            result = (Product) broker.getObjectByQuery(query);
        }
        finally
        {
            if (broker != null) broker.close();
        }

        if (result != null)
            System.out.println("HELLO" + result.getName());
        return result;
    }

This is the tutorial code, modifies slightly.

Here is my main function:

    public static void main(String[] args)
    {
        Product newProduct = new Product();
        Product product = null;
        newProduct.setName("Sprocket");

        product = ProductDAO.findByTemplate(newProduct);
        System.out.println(product.getName());

    }

and here is my binding:

<class-descriptor
       class="au.com.tt.holpub.beans.Product"
       table="Product"
>
    <field-descriptor
       name="id"
       column="id"
       primarykey="true"
       autoincrement="false"
    />
    <field-descriptor
       name="name"
       column="name"
    />
    <field-descriptor
       name="price"
       column="price"
    />
    <field-descriptor
       name="stock"
       column="stock"
    />
</class-descriptor>

I have bumped up the root logging level to debug and here is the output:


[org.apache.ojb.broker.metadata.ConnectionRepository] DEBUG: New
descriptor was added: org.apache.ojb.broker.metadata.Jd
bcConnectionDescriptor@15f5897[
  jcd-alias=default
  default-connection=true
  dbms=PostgreSQL
  jdbc-level=3.0
  driver=org.postgresql.Driver
  protocol=jdbc
  sub-protocol=postgresql
  db-alias=//localhost/test
  user=kamal
  password=*****
  eager-release=false
  ConnectionPoolDescriptor={whenExhaustedAction=0, maxIdle=-1,
maxActive=30, maxWait=10000, removeAbandoned=false, numTe
stsPerEvictionRun=10, minEvictableIdleTimeMillis=600000,
testWhileIdle=false, testOnReturn=false, logAbandoned=false, mi
nIdle=0, fetchSize=0, removeAbandonedTimeout=300,
timeBetweenEvictionRunsMillis=-1, testOnBorrow=true}
  batchMode=false
  useAutoCommit=AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE
  ignoreAutoCommitExceptions=false
  sequenceDescriptor=org.apache.ojb.broker.metadata.SequenceDescriptor@186d4c1[
     sequenceManagerClass=class
org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl
     Properties={autoNaming=true, seq.start=200000, grabSize=20}
]
]
[org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl] INFO: Create
new PB instance for PBKey org.apache.ojb.brok
er.PBKey: jcdAlias=default, user=kamal, password=*****, already created
persistence broker instances: 0
[org.apache.ojb.broker.cache.ObjectCacheFactory] INFO: Start creating new
ObjectCache instance
[org.apache.ojb.broker.cache.ObjectCacheFactory] INFO: Instantiate new
org.apache.ojb.broker.cache.CacheDistributor for
PB instance org.apache.ojb.broker.core.PersistenceBrokerImpl@b82368
[org.apache.ojb.broker.cache.ObjectCacheFactory] INFO: New ObjectCache
instance was created
[org.apache.ojb.broker.util.sequence.SequenceManagerFactory] DEBUG:
Default sequence manager class was org.apache.ojb.br
oker.util.sequence.SequenceManagerHighLowImpl
[org.apache.ojb.broker.util.sequence.SequenceManagerFactory] DEBUG: create
new sequence manager for broker org.apache.oj
b.broker.core.PersistenceBrokerImpl@b82368
[org.apache.ojb.broker.util.sequence.SequenceManagerFactory] DEBUG:
Jdbc-Connection-Descriptor 'default' use sequence ma
nager: class org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl
[org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement$TableAlias]
DEBUG: TableAlias(): using hints ? false
[org.apache.ojb.broker.accesslayer.StatementManager] DEBUG: closeResources
was called

When I return from my selection function I get no results.

Any clues?

Cheers.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.