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 Thomas Franke <fr...@softenergy.de> on 2004/11/15 15:16:09 UTC

join with ojb

Hallo there,

I want to do this with ojb but I can't find a good and straight forward way.

SELECT DISTINCT A.name
FROM adressen A, adressen_adressart_typ B, adressartandtyp C
WHERE A.adressen_id = B.adressen_id
AND B.adressart_id = C.adressart_id
AND C.adressart = 1;

Could anyone give me a simple solution?

Thanks in advance.

regards

Thomas


-- 
Mit freundlichen Grüßen

Thomas Franke

Geschäftsführer softEnergy GmbH
----------------------------
The energy for a better world
----------------------------
softEnergy GmbH
Platz der Freundschaft 1
18059 Rostock
----------------------------
fon: +49 381 40 587 535
fax: +49 381 40 587 555
mobil: +49 1715222015

http://www.softenergy.de
mail: info@softenergy.de
----------------------------

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


Re: join with ojb

Posted by Thomas Franke <fr...@softenergy.de>.
Danilo Tommasina wrote:

> 
> Ok, then try something like this:
> 
> Criteria crit = new Criteria();
> crit.addEqualTo( "<ref To Adressen_adressart_typ>.<ref To 
> Adressartandtyp>.addressart", new Integer( 1 ) );
> 
> QueryByCriteria query = new QueryByCriteria( Adressen.class, crit, true );
> 
> PersistenceBroker pb = null;
> try {
>   pb = PersistenceBrokerFactory.defaultPersistenceBroker();
> 
>   Collection results = pb.getCollectionByQuery( query );
> 
>   // The Collection now contains instances of class Adressen
> 
> } catch ( Exception e ) {
>   // Do exception handling
> } finally {
>   if ( pb != null ) {
>      pb.close();
>   }
> }
First I don't understand how I can use a collection-descriptor as a 
reference in my statement. Now I got it. Thanx for help.

<collection-descriptor
          name="roles"
          element-class-ref="org.apache.ojb.broker.Role"
       >
          <inverse-foreignkey field-ref="person_id"/>
</collection-descriptor>

regards

Thomas

-- 
Mit freundlichen Grüßen

Thomas Franke

Geschäftsführer softEnergy GmbH
----------------------------
The energy for a better world
----------------------------
softEnergy GmbH
Platz der Freundschaft 1
18059 Rostock
----------------------------
fon: +49 381 40 587 535
fax: +49 381 40 587 555
mobil: +49 1715222015

http://www.softenergy.de
mail: info@softenergy.de
----------------------------

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


Re: join with ojb

Posted by Thomas Franke <fr...@softenergy.de>.
Danilo Tommasina wrote:

> 
> Ok, then try something like this:
> 
> Criteria crit = new Criteria();
> crit.addEqualTo( "<ref To Adressen_adressart_typ>.<ref To 
> Adressartandtyp>.addressart", new Integer( 1 ) );
<ref To Adressen_adressart_typ> is a collection. Can I do this with a 
collection? I try it. The reference in our address mapping looks like this:

<collection-descriptor
  name="adressen_adressart_typ"
  element-class-ref="de.softenergy.exampel.AddressAndAddressType"
  auto-retrieve="true"
  auto-update="false"
  auto-delete="false" >
  <inverse-foreignkey field-ref="address_id"/>
</collection-descriptor>


regards

Thomas

-- 
Mit freundlichen Grüßen

Thomas Franke

Geschäftsführer softEnergy GmbH
----------------------------
The energy for a better world
----------------------------
softEnergy GmbH
Platz der Freundschaft 1
18059 Rostock
----------------------------
fon: +49 381 40 587 535
fax: +49 381 40 587 555
mobil: +49 1715222015

http://www.softenergy.de
mail: info@softenergy.de
----------------------------

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


Re: join with ojb

Posted by Danilo Tommasina <dt...@risksys.com>.
Ok, then try something like this:

Criteria crit = new Criteria();
crit.addEqualTo( "<ref To Adressen_adressart_typ>.<ref To Adressartandtyp>.addressart", new Integer( 1 ) );

QueryByCriteria query = new QueryByCriteria( Adressen.class, crit, true );

PersistenceBroker pb = null;
try {
   pb = PersistenceBrokerFactory.defaultPersistenceBroker();

   Collection results = pb.getCollectionByQuery( query );

   // The Collection now contains instances of class Adressen

} catch ( Exception e ) {
   // Do exception handling
} finally {
   if ( pb != null ) {
      pb.close();
   }
}


> Danilo Tommasina wrote:
> 
> Thanks a lot for your help.
> 
>> With the PersistenceBroker API you can use a ReportQueryByCriteria
> 
> O.K., but we want as result a collection with 'Address' objects. The 
> 'name' attribute is an exampel only. Sorry, my question was not clear 
> enough. We don't know the right mapping and how to build the 'Criteria' 
> object.
> 
> regards
> 
> Thomas
> 


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


Re: join with ojb

Posted by Thomas Franke <fr...@softenergy.de>.
Danilo Tommasina wrote:

Thanks a lot for your help.

> With the PersistenceBroker API you can use a ReportQueryByCriteria
O.K., but we want as result a collection with 'Address' objects. The 
'name' attribute is an exampel only. Sorry, my question was not clear 
enough. We don't know the right mapping and how to build the 'Criteria' 
object.

regards

Thomas

-- 
Mit freundlichen Grüßen

Thomas Franke

Geschäftsführer softEnergy GmbH
----------------------------
The energy for a better world
----------------------------
softEnergy GmbH
Platz der Freundschaft 1
18059 Rostock
----------------------------
fon: +49 381 40 587 535
fax: +49 381 40 587 555
mobil: +49 1715222015

http://www.softenergy.de
mail: info@softenergy.de
----------------------------

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


Re: join with ojb

Posted by Danilo Tommasina <dt...@risksys.com>.
Hi,

What you are doing is using inner joins with legacy Oracle or Sybase syntax (and probably several other DBs).

With the PersistenceBroker API you can use a ReportQueryByCriteria

something like this:

Criteria crit = new Criteria();
crit.addEqualTo( "<ref To Adressen_adressart_typ>.<ref To Adressartandtyp>.addressart", new Integer( 1 ) );

ReportQueryByCriteria query = new ReportQueryByCriteria( Adressen.class, new String [] { "name" }, crit, true );

PersistenceBroker pb = null;
try {
   pb = PersistenceBrokerFactory.defaultPersistenceBroker();

   Iterator results = pb.getReportQueryIteratorByQuery( query );

   // Extract the value you need before closing the PersistenceBroker
   // The Iterator entries are Object [] containing a single String representing the name
   // String name = (String) ((Object []) results.next())[ 0 ];


} catch ( Exception e ) {
   // Do exception handling
} finally {
   if ( pb != null ) {
      pb.close();
   }
}

Modify the addEqualTo( ... ) statement according to your repository.xml, without this file i cannot help more.

bye
Danilo


> Hallo there,
> 
> I want to do this with ojb but I can't find a good and straight forward 
> way.
> 
> SELECT DISTINCT A.name
> FROM adressen A, adressen_adressart_typ B, adressartandtyp C
> WHERE A.adressen_id = B.adressen_id
> AND B.adressart_id = C.adressart_id
> AND C.adressart = 1;
> 
> Could anyone give me a simple solution?
> 
> Thanks in advance.
> 
> regards
> 
> Thomas
> 
> 


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