You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Mahler Thomas <th...@itellium.com> on 2003/09/12 10:49:43 UTC

RE: Really difficult OJB question - Help!

Hi Rick,
 
please post further requests to the ojb user list, not to developers
directly.
 
To answer you question.
If you select a person object, OJB will load all Application objects that
belong to that person.
 
You have to selct from the Application class and must use criteria that
specify the person and other restricting criteria to select only certain
application objects for a given user.
 
cheers,
Thomas 
 

-----Original Message-----
From: Rick Banerjee [mailto:rickb@merindus.com]
Sent: Friday, September 12, 2003 7:00 AM
To: thomas.mahler@itellium.com; thomas.mahler@home.ins.de
Subject: Really difficult OJB question - Help!


Hello Thomas,

I have a particularly difficult situation while using OJB for my project and
I hope you could help me out.

This is the situation:

I have two tables called PERSON and APPLICATION. They are joined by the
column IDN_TRACKINGNUMBER. The mapping from Person to 
Application is of the type 1:n, i.e. a person can have 0 to N applications. 

I was using broker.getCollectionByQuery to retrieve objects of type Person
(which represents the table PERSON). The problem is after
I retrieve Person objects, I do the following:

// Criteria contains columns from both PERSON & APPLICATION
searchQuery = new QueryByCriteria(Person.class, searchCriteria);
Collection c = broker.getCollectionByQuery (criteria);
// Iterate and retrieve Person objects.
// p is the Person object retrieved.
// Trying to get all the applications that this Person has that match the
criteria provided via searchCriteria.
p.getAllApplications();

Here I must mention that the Person value-object contains a Collection
called allApplication to hold all the applications belonging to a Person.
But, when I make this call, I get back ALL applications although I had
specified Application related search criteria in the query used to retrieve
Person objects.

So, I am getting every application associated with the Person in question
instead of just getting back just those that satisfy the criteria that I
have specified, because p.getAllApplications() makes a call to the DB and
ignores all previous criteria.

What can I do to retrieve just the applications that match the criteria when
I call getAllApplications().

I have tried using extents, ReportQueries, and also examined
QueryCustomizers.

Thanks and Regards

RB



Re: PATCH from users list Re: reverse-db issue:

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi jason,

thanks for the patch, it's in the repository now.

jakob

Jason Pyeron wrote:

>Index: src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java
>===================================================================
>RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java,v
>retrieving revision 1.8
>diff -u -B -r1.8 DBSchema.java
>--- src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java	29 Jun 2003 14:28:07 -0000	1.8
>+++ src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java	13 Sep 2003 16:21:25 -0000
>@@ -124,8 +124,9 @@
>       // Pointbase returns the catalog name in uppercase here and in mixed
>       // case in getCatalogs(). Therefore we have to use toUpper().
>       if (   
>-             (strTableCat == null && this.getDBCatalog().getCatalogName() == null || strTableCat.equalsIgnoreCase(this.getDBCatalog().getCatalogName()))
>-           &&(strSchemaName == null && this.getSchemaName() == null || strSchemaName.equals(this.getSchemaName()))
>+          (strTableCat!=null && strTableCat.equalsIgnoreCase(this.getDBCatalog().getCatalogName()) || strTableCat==this.getDBCatalog().getCatalogName())
>+          &&
>+          (strSchemaName!=null && strSchemaName.equals(this.getSchemaName()) || strSchemaName==this.getSchemaName())
>          )
>         this.addTable(strTableName, strTableType);
>       
>
>
>
>On Sat, 13 Sep 2003, Jason Pyeron wrote:
>
>  
>
>>any one get this before?
>>
>>this was after the read button was pushed.
>>
>>[jpyeron@MrLaptop db-ojb-1.0.rc4]$ ant reverse-db
>>Buildfile: build.xml
>>
>>reverse-db:
>>[reversedb] Using MySQL-AB JDBC Driver 3.0.8-stable ( $Date: 2003/05/19 00:57:19 $, $Revision: 1.27.2.18 $ )
>>[reversedb] java.lang.NullPointerException
>>[reversedb]     at org.apache.ojb.tools.mapping.reversedb.DBSchema.read(DBSchema.java:126)
>>[reversedb]     at org.apache.ojb.tools.mapping.reversedb.DBCatalog.read(DBCatalog.java:164)
>>[reversedb]     at org.apache.ojb.tools.mapping.reversedb.DBMeta.read(DBMeta.java:224)
>>[reversedb]     at org.apache.ojb.tools.mapping.reversedb.gui.JFrmMainFrame.analyzeSchema(JFrmMainFrame.java:128)
>>
>>Sincerely,
>>
>>Jason Pyeron
>>
>>
>>    
>>
>
>  
>
>------------------------------------------------------------------------
>
>Index: src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java
>===================================================================
>RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java,v
>retrieving revision 1.8
>diff -u -B -r1.8 DBSchema.java
>--- src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java	29 Jun 2003 14:28:07 -0000	1.8
>+++ src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java	13 Sep 2003 16:21:25 -0000
>@@ -124,8 +124,9 @@
>       // Pointbase returns the catalog name in uppercase here and in mixed
>       // case in getCatalogs(). Therefore we have to use toUpper().
>       if (   
>-             (strTableCat == null && this.getDBCatalog().getCatalogName() == null || strTableCat.equalsIgnoreCase(this.getDBCatalog().getCatalogName()))
>-           &&(strSchemaName == null && this.getSchemaName() == null || strSchemaName.equals(this.getSchemaName()))
>+          (strTableCat!=null && strTableCat.equalsIgnoreCase(this.getDBCatalog().getCatalogName()) || strTableCat==this.getDBCatalog().getCatalogName())
>+          &&
>+          (strSchemaName!=null && strSchemaName.equals(this.getSchemaName()) || strSchemaName==this.getSchemaName())
>          )
>         this.addTable(strTableName, strTableType);
>       
>  
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-dev-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


PATCH from users list Re: reverse-db issue:

Posted by Jason Pyeron <ja...@pyeron.com>.
Index: src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java
===================================================================
RCS file: /home/cvspublic/db-ojb/src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java,v
retrieving revision 1.8
diff -u -B -r1.8 DBSchema.java
--- src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java	29 Jun 2003 14:28:07 -0000	1.8
+++ src/java/org/apache/ojb/tools/mapping/reversedb/DBSchema.java	13 Sep 2003 16:21:25 -0000
@@ -124,8 +124,9 @@
       // Pointbase returns the catalog name in uppercase here and in mixed
       // case in getCatalogs(). Therefore we have to use toUpper().
       if (   
-             (strTableCat == null && this.getDBCatalog().getCatalogName() == null || strTableCat.equalsIgnoreCase(this.getDBCatalog().getCatalogName()))
-           &&(strSchemaName == null && this.getSchemaName() == null || strSchemaName.equals(this.getSchemaName()))
+          (strTableCat!=null && strTableCat.equalsIgnoreCase(this.getDBCatalog().getCatalogName()) || strTableCat==this.getDBCatalog().getCatalogName())
+          &&
+          (strSchemaName!=null && strSchemaName.equals(this.getSchemaName()) || strSchemaName==this.getSchemaName())
          )
         this.addTable(strTableName, strTableType);
       



On Sat, 13 Sep 2003, Jason Pyeron wrote:

> any one get this before?
> 
> this was after the read button was pushed.
> 
> [jpyeron@MrLaptop db-ojb-1.0.rc4]$ ant reverse-db
> Buildfile: build.xml
> 
> reverse-db:
> [reversedb] Using MySQL-AB JDBC Driver 3.0.8-stable ( $Date: 2003/05/19 00:57:19 $, $Revision: 1.27.2.18 $ )
> [reversedb] java.lang.NullPointerException
> [reversedb]     at org.apache.ojb.tools.mapping.reversedb.DBSchema.read(DBSchema.java:126)
> [reversedb]     at org.apache.ojb.tools.mapping.reversedb.DBCatalog.read(DBCatalog.java:164)
> [reversedb]     at org.apache.ojb.tools.mapping.reversedb.DBMeta.read(DBMeta.java:224)
> [reversedb]     at org.apache.ojb.tools.mapping.reversedb.gui.JFrmMainFrame.analyzeSchema(JFrmMainFrame.java:128)
> 
> Sincerely,
> 
> Jason Pyeron
> 
> 

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- Jason Pyeron                   http://www.pyerotechnics.com   -
- Partner & Sr. Manager         Pyerotechnics Development, Inc. -
-                               500 West University Parkway #1S -
- +1 (410) 808-6646             Baltimore, Maryland  21210-3253 -
-                                                               -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

This message is for the designated recipient only and may contain 
privileged, proprietary, or otherwise private information. If you 
have received it in error, purge the message from your system and 
notify the sender immediately.  Any other use of the email by you 
is prohibited.



reverse-db issue:

Posted by Jason Pyeron <ja...@pyeron.com>.
any one get this before?

this was after the read button was pushed.

[jpyeron@MrLaptop db-ojb-1.0.rc4]$ ant reverse-db
Buildfile: build.xml

reverse-db:
[reversedb] Using MySQL-AB JDBC Driver 3.0.8-stable ( $Date: 2003/05/19 00:57:19 $, $Revision: 1.27.2.18 $ )
[reversedb] java.lang.NullPointerException
[reversedb]     at org.apache.ojb.tools.mapping.reversedb.DBSchema.read(DBSchema.java:126)
[reversedb]     at org.apache.ojb.tools.mapping.reversedb.DBCatalog.read(DBCatalog.java:164)
[reversedb]     at org.apache.ojb.tools.mapping.reversedb.DBMeta.read(DBMeta.java:224)
[reversedb]     at org.apache.ojb.tools.mapping.reversedb.gui.JFrmMainFrame.analyzeSchema(JFrmMainFrame.java:128)

Sincerely,

Jason Pyeron

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- Jason Pyeron                   http://www.pyerotechnics.com   -
- Partner & Sr. Manager         Pyerotechnics Development, Inc. -
-                               500 West University Parkway #1S -
- +1 (410) 808-6646             Baltimore, Maryland  21210-3253 -
-                                                               -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

This message is for the designated recipient only and may contain 
privileged, proprietary, or otherwise private information. If you 
have received it in error, purge the message from your system and 
notify the sender immediately.  Any other use of the email by you 
is prohibited.






---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Inheritance querying problem

Posted by shibin ck <ck...@yahoo.com>.
Hi,
    Thank you very much for replying.     
     Actually my problem is not of aggregation, its of inheritance. B is inheriting from A. You need not have an attribute of A in B for this.  
the "super" attribute in reference descriptor is not an actual attribute of B , but it is used to inform ojb that A is the super class of B
 
here is a snip from  http://db.apache.org/ojb/tutorial3.html        (  Advanced Object Relational Mapping techniques --->  mapping inheritance hierarchies ---> mapping classes on multiple joined tables)
=============================================
As you can see from this mapping we need a special reference-descriptor that advises OJB to load the values for the inherited attributes from class A by a JOIN using the (B.id == A.id) foreign key reference.

The name="super" is not used to address an actual attribute of the class B but as a marker keyword defining the JOIN to the baseclass. 
==============================================
 
This strategy is one of the three strategies used for mapping inheritance hierarchies to tables. I get objects of both A and B when queried on class A  If i use other strategies (using <extent-class> tag) . But when i use "super" method , i only get A objects (B objects are stripped to A so i dont get B's attributes).
Since table structures are already decided in our project, we have to use "super" method.
 
Again my goal is to query on A.class to retrive objects of both A.class and B.class
 
Thanks
shibin
 

LAURENT Stephane <sl...@adequates.com> wrote:
Sorry but when I look this :


I think your class is like this :
class B 
{
private int id;
private String email;
private A super;

/* getters and setters*/
} 

So, it's an agregation (also extends but where is your type A attribute in B ?) and you can add criteria("B.super",null)

Not sure to understand your goal ...


---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

Re: Inheritance querying problem

Posted by LAURENT Stephane <sl...@adequates.com>.
Sorry but when I look this :
<class-descriptor  class="B"  table="B">
    <field-descriptor  name="id"  column="ID"  jdbc-type="INTEGER"  primarykey="true"  autoincrement="true"/>
    <field-descriptor  name="email"  column="EMAIL"  jdbc-type="VARCHAR"/>
        <reference-descriptor  name="super"  class-ref="A">
            <foreignkey field-ref="id"/>
        </reference-descriptor>
</class-descriptor>

I think your class is like this :
class B 
{
 private int id;
 private String email;
 private A super;
 
 /* getters and setters*/
} 

So, it's an agregation (also extends but where is your type A attribute in B ?) and you can add criteria("B.super",null)

Not sure to understand your goal ...
  ----- Original Message ----- 
  From: shibin ck 
  To: OJB Users List 
  Sent: Friday, September 12, 2003 11:38 AM
  Subject: Inheritance querying problem 



  Hi,


     i have 2 classes A and B. B inherits from A. i map classes A and B on multiple joined tables.

  my classes are

  class A
  {
   private int id;
   private String name;
   
   /* getters and setters*/
  }
  class B extends A
  {
   private int id;
   private String email;
   
   /* getters and setters*/
  } 

   my descriptor file is like
     
  <class-descriptor  class="A"  table="A">
      <field-descriptor  name="id"  column="ID"  jdbc-type="INTEGER"  primarykey="true"  autoincrement="true"/>
      <field-descriptor  name="name"  column="NAME"  jdbc-type="VARCHAR"/>
  </class-descriptor>

  <class-descriptor  class="B"  table="B">
      <field-descriptor  name="id"  column="ID"  jdbc-type="INTEGER"  primarykey="true"  autoincrement="true"/>
      <field-descriptor  name="email"  column="EMAIL"  jdbc-type="VARCHAR"/>
          <reference-descriptor  name="super"  class-ref="A">
              <foreignkey field-ref="id"/>
          </reference-descriptor>
  </class-descriptor>

  The problem is when i query on A class with null criteria .. it returns objects of A only
  ie
  QueryByCriteria queryOne = new QueryByCriteria (A.class, null);
  Collection col = broker.getCollectionByQuery (queryOne);

  Iterator iter = col.iterator ();
  while (iter.hasNext ())
  {
      System.out.println(iter.next().getClass());  
  } 
  this prints class A only ... (i'm getting B objects as A objects so i am able to get name of B objects but not  email) ..

  If i use each class in separate table (with <extent> tag) ... it is working fine (class A and class B are printing)

  So my question is 
   is there any way by which we can get child attributes by quering on parent class using <reference-descriptor name="super" ... method???

  Thanks in advance

  shibin 


  ---------------------------------
  Do you Yahoo!?
  Yahoo! SiteBuilder - Free, easy-to-use web site design software


  ---
  Outgoing mail is certified Virus Free.
  Checked by AVG anti-virus system (http://www.grisoft.com).
  Version: 6.0.518 / Virus Database: 316 - Release Date: 11/09/2003

Inheritance querying problem

Posted by shibin ck <ck...@yahoo.com>.
Hi,


   i have 2 classes A and B. B inherits from A. i map classes A and B on multiple joined tables.

my classes are

class A
{
 private int id;
 private String name;
 
 /* getters and setters*/
}
class B extends A
{
 private int id;
 private String email;
 
 /* getters and setters*/
} 

 my descriptor file is like
   
<class-descriptor  class="A"  table="A">
    <field-descriptor  name="id"  column="ID"  jdbc-type="INTEGER"  primarykey="true"  autoincrement="true"/>
    <field-descriptor  name="name"  column="NAME"  jdbc-type="VARCHAR"/>
</class-descriptor>

<class-descriptor  class="B"  table="B">
    <field-descriptor  name="id"  column="ID"  jdbc-type="INTEGER"  primarykey="true"  autoincrement="true"/>
    <field-descriptor  name="email"  column="EMAIL"  jdbc-type="VARCHAR"/>
        <reference-descriptor  name="super"  class-ref="A">
            <foreignkey field-ref="id"/>
        </reference-descriptor>
</class-descriptor>

The problem is when i query on A class with null criteria .. it returns objects of A only
ie
QueryByCriteria queryOne = new QueryByCriteria (A.class, null);
Collection col = broker.getCollectionByQuery (queryOne);

Iterator iter = col.iterator ();
while (iter.hasNext ())
{
    System.out.println(iter.next().getClass());  
} 
this prints class A only ... (i'm getting B objects as A objects so i am able to get name of B objects but not  email) ..

If i use each class in separate table (with <extent> tag) ... it is working fine (class A and class B are printing)

So my question is 
 is there any way by which we can get child attributes by quering on parent class using <reference-descriptor name="super" ... method???

Thanks in advance

shibin 


---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software