Filtering on join of a join

2007-12-22 Thread Kamal Bhatt
Hi,
I have the following tables:
CREATE TABLE style (
style_idCHARACTER VARYING (10)  NOT NULL,
has_links   BOOLEAN DEFAULT   (false),
description CHARACTER VARYING   NOT NULL,
PRIMARY KEY (style_id)
);

CREATE TABLE style_fld (
style_fld_id CHARACTER VARYING (20) NOT NULL,
styleCHARACTER VARYING (10) NOT NULL,
fld_type CHARACTER VARYING (10) NOT NULL DEFAULT 'STRING',
position SMALLINT   NOT NULL,
labelCHARACTER VARYING  NOT NULL,
help CHARACTER VARYING  NOT NULL,
xml_elem CHARACTER VARYING (200) NOT NULL ,
PRIMARY KEY (style_fld_id)
);

CREATE TABLE style_value (
style_fld CHARACTER VARYING (20)NOT NULL,
brand CHARACTER VARYING (8),
value CHARACTER VARYING NOT NULL,
PRIMARY KEY (style_fld, brand)
);

I have created the following mappings:


  
  
  

  

  



  
  
  
  
  
  

  

  



  
  
  


Now, I want to get all the styles, and all the associated style_flds all
the associated style_values that match a particular brand.

I was thinking something like this:

Criteria crit = new Criteria();
crit.addEqualTo("style_value.brand", inBrand.getBrandId());
QueryByCriteria query = QueryFactory.newQuery(Style.class, crit);
Iterator iter = broker.getIteratorByQuery(query);

would work for me, but it doesn't. Unfortunately, the docs are not clear
about what to do in this scenario. Also, I would like this to be a left
outer join.

Any help would be appreciated.

Thanks.



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



Left outer join scenario

2007-12-18 Thread Kamal Bhatt

Hi,
I have a the following scenario. I have three tables - Key, Value, 
Styling. Now a Value belongs to a Key and a Styling. The "primary" table 
in this case is Styling (ie, the table where all the action is centred on).


Normally, this would be a "simple" m:n relatioship, however, when I 
retrieve the content, I want to include all Key objects, regardless of 
whether there is a Value or not. This, obviously, is so I can display 
all Keys for the user to edit. Now, I think the solution to this problem 
is to set auto-retrieve to "false" and auto-update and auto-delete to 
"true" for the Key/Value/Styling relationships and loading the content 
separately, and before I load the content back, remove all empty values.


This seems very yucky but workable. That said, there seem to be a lot of 
caveats including:
'When using a top-level api (ODMG, OTM, JDO) it is *mandatory to use 
specific auto-xxx settings*.


For OTM- and JDO-api the settings are:
- /auto-retrieve="true"/
- /auto-update="false"/
- /auto-retrieve="false"/
This are at the same time the /default/ auto-XXX settings (so don't 
specify any of this attributes will have the same effect).


For the ODMG-api the mandatory settings are (since OJB 1.0.2):
- /auto-retrieve="true"/
- /auto-update="none"/
- /auto-retrieve="none"'


And:

/'Be careful when using "opposite" settings, e.g. if you declare a 1:1 
reference with auto-retrieve="false" BUT auto-update="object" (or "true" 
or "link").
Before you can perform an update on the main object, you have to 
"retrieve" the 1:1 reference. Otherwise you will end up with an 
nullified reference enty in main object, because OJB doesn't find the 
referenced object on update and assume the reference was removed.'


Now, I think, the first one stops me from doing this, though I will be 
honest and admit I don't understand what this is trying to say. How do I 
know if I am using OTM/ODMG/JDO? I think I am using the PersistentBroker 
(I am instantiating a PersistentBroker class) I think the second one 
probably doesn't apply to me, but I just want to make sure of that.


Is there a nicer way of doing this scenario?

Thanks.

--
Kamal Bhatt


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



Re: QueryByCriteria is not working

2006-10-09 Thread Kamal Bhatt


 
Do you have any primitive type properties in Product object - int, 
long ...?

Yes I did. Thanks.


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





--
Kamal Bhatt


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



QueryByCriteria is not working

2006-10-09 Thread Kamal Bhatt
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:








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
[EMAIL PROTECTED]
  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=1, removeAbandoned=false, numTe
stsPerEvictionRun=10, minEvictableIdleTimeMillis=60,
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
  [EMAIL PROTECTED]
 sequenceManagerClass=class
org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl
 Properties={autoNaming=true, seq.start=20, 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 [EMAIL PROTECTED]
[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
[EMAIL PROTECTED]
[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.



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



Re: Incorrect or not found field reference name

2006-09-20 Thread Kamal Bhatt

NM.

Worked it out. The reference-descriptor was pointing to the column 
heading instead of the id.


Cheers.

--
Kamal Bhatt


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



Incorrect or not found field reference name

2006-09-20 Thread Kamal Bhatt
(BrandClass inBrandClass) { mBrandClass = 
inBrandClass; }


   /* 
 
*/
   /** Wrapper for mBrandClass.setLabel.
   */
   /* 
 
*/
 
   public void setLabel(String inLabel) { mBrandClass.setLabel(inLabel); }
  
   /* 
 
*/
   /** Wrapper for mBrandClass.setRequired.
   */
   /* 
 
*/
 
   public void setIsRequired(boolean inIsRequired) { 
mBrandClass.setIsRequired(inIsRequired); }
  
   /* 
 
*/
   /** set Id.
   */
   /* 
 
*/
 
   public void setId(int inId) { mId = inId;  }
  
   /* 
= 
*/
   /* PRIVATE MEMBERS
*/
   /* 
= 
*/
 
   private intmId;// Required for OJB binding

   private StringmValue;
   private BrandClassmBrandClass;
}

Here are the relevant mappings:
   
   jdbc-type="VARCHAR" primarykey="true"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="BOOLEAN"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="BOOLEAN"/>

   
   jdbc-type="VARCHAR"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="VARCHAR"/>
   jdbc-type="VARCHAR"/>


   element-class-ref="creative.beans.BrandParam" auto-retrieve="true"

   auto-update="true" auto-delete="true">
   
   

   element-class-ref="creative.beans.ExtraEnqField" auto-retrieve="true"

   auto-update="true" auto-delete="true">
   
  
   
  
  
   jdbc-type="INTEGER" primarykey="true" default-fetch="true"

   access="anonymous"/>
   jdbc-type="INTEGER" primarykey="true"/>

   
   class-ref="creative.beans.BrandClass" auto-update="none" auto-delete="none"

   auto-retrieve="true">
   
   
   

   
   primarykey="true" autoincrement="true"

   sequence-name="brand_class_id_seq"/>
   
   jdbc-type="BOOLEAN"/>

   

   table="extra_enq_field">
   default-fetch="true" access="anonymous"/>
   primarykey="true" autoincrement="true"

   sequence-name="extra_enq_field_id_seq"/>
   
   jdbc-type="VARCHAR"/>
  


Any help would be appreciated.

--
Kamal Bhatt


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