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 Dirk Manske <me...@dirkmanske.de> on 2004/01/14 01:58:06 UTC

Two 1:N mappings to one table

Hi,

how can I map two tables with each having a 1:N relation to the same table?
I always get a null pointer exception for class Person. 

I have three tables:

PERSON with a 1:N relation to ACTIVITY 

and

VENTURE with a 1:N relation to ACTIVITY

Table PERSON and VENTURE both references activityId from table ACTIVITY. In
the repository-user.xml for each table which relates to ACTIVITY the
collection-descriptor is setup 

for table VENTURE:

<collection-descriptor
name="allAssignedActivities"
element-class-ref="de.plato.Activity"
orderBy="activityId"
sort="DESC"
auto-update="true" >
<inverse-foreignkey field-ref="ventureId" />
</collection-descriptor>

and for table PERSON:

<collection-descriptor
name="allAssignedActivities"
element-class-ref="de.plato.Activity"
orderBy="activityId"
sort="DESC"
auto-update="true" >
<inverse-foreignkey field-ref="personId" />
</collection-descriptor>

for ACTIVITY, both tables are referenced:

<reference-descriptor name="person">
class-ref="de.plato.Person"
refresh="true"
auto-retrieve="true">
<foreign-key field-ref="personId" />

and

<reference-descriptor name="venture">
class-ref="de.plato.Venture"
refresh="true"
auto-retrieve="true">
<foreign-key field-ref="ventureId" />

Unfortunately, this does not work. What do I have to do?

thx,
Dirk


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


Re: Apologies

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi Guillaume,

Guillaume Nodet wrote:

> I apologies to all of you and especially to Gopi Nandamuri
> for the mail i posted a few days ago on this mailing list.
> My intention was not to offend Gopi and in fact i
> completely misunderstood his questions. In the future,
> i will pay close attention, before replying to a mail,
> to be sure to have really understood the meaning and to
> be able to give something consistent as a reply.
> 

We all make mistakes (except most managers) ;-)

> As a good will and amendment gesture i want to propose the following
> code of a PersistentField that i wrote to solve a problem i had
> with nested fields.

Thanks for this contribution and detailed description (I understand the 
problem ;-)). I will add a test for this problem and adopt your fix 
ASAP. Thanks!

regards,
Armin

> I think that the problem is not restrained to me.
> The problem arise when using nested objects that can be nulled.
> Actually, when ojb reads the first field of a nested object that is
> null, an instance is created to continue the recursive walk through
> the nested objects, even if the given value to set for the attribute
> is null. So i needed to make two modifications for the process to work.
> 
>   * first i had overriden the 'set' method of the AbstractPersistentField
>     class to early test if the value will not be set. The added test is
>     borrowed from the PersistentFieldDirectAccessImpl but is performed
>     before having created an instance of the nested object.
> 
>     public void set(Object targetObject, Object value) throws
> MetadataException
>     {
>         if (isNestedField())
>         {
>         	if (value != null || !getField().getType().isPrimitive())
>         	{
>             	setNestedObject(targetObject, fieldName, value);
>             }
>         }
>         else
>         {
>             doSet(targetObject, value);
>         }
>     }
> 
> 
>    * the second modification i did is needed because the test on the 'set'
> method
>      works only for primitive types. But if we store a Date for example in a
> nested
>      object, it will be nevertheless created. But the test can not extend
> the test
>      made earlier, because if we nested objects could have non-null default
> values
>      for certain fields.  So i overrided the 'setNestedObject' method to
> perform
>      the test so that when realizing that the nested object is null, there
> is no need
>      to create one to put a null value in the field.
>      When the added test 'if (attrib != null || value != null)' is true
>      the instanciation and setting of the attribute is skipped.
> 
>     protected void setNestedObject(Object obj, String fieldName, Object
> value)
>     {
>         int index = fieldName.indexOf(PATH_TOKEN);
>         if (index >= 0)
>         {
>             String name = fieldName.substring(0, index);
>             PersistentField pField =
> createInternPersistentField(ProxyHelper.getRealClass(obj), name);
>             Object attrib = pField.get(ProxyHelper.getRealObject(obj));
>             if (attrib != null || value != null)
>             {
>                   if (attrib == null)
>                   {
>                     .......
> 	            }
> 	            String nestedName = fieldName.substring(index +
> PATH_TOKEN.length());
> 	            setNestedObject(attrib, nestedName, value);
> 	        }
>         }
>         else
>         {
>             PersistentField pField =
> createInternPersistentField(ProxyHelper.getRealClass(obj), fieldName);
>             pField.set(ProxyHelper.getRealObject(obj), value);
>         }
> 
>     }
> 
> Best regards,
> 
> Guillaume Nodet
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 



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


Apologies

Posted by Guillaume Nodet <gu...@deliasystems.com>.
I apologies to all of you and especially to Gopi Nandamuri
for the mail i posted a few days ago on this mailing list.
My intention was not to offend Gopi and in fact i
completely misunderstood his questions. In the future,
i will pay close attention, before replying to a mail,
to be sure to have really understood the meaning and to
be able to give something consistent as a reply.

As a good will and amendment gesture i want to propose the following
code of a PersistentField that i wrote to solve a problem i had
with nested fields. I think that the problem is not restrained to me.
The problem arise when using nested objects that can be nulled.
Actually, when ojb reads the first field of a nested object that is
null, an instance is created to continue the recursive walk through
the nested objects, even if the given value to set for the attribute
is null. So i needed to make two modifications for the process to work.

  * first i had overriden the 'set' method of the AbstractPersistentField
    class to early test if the value will not be set. The added test is
    borrowed from the PersistentFieldDirectAccessImpl but is performed
    before having created an instance of the nested object.

    public void set(Object targetObject, Object value) throws
MetadataException
    {
        if (isNestedField())
        {
        	if (value != null || !getField().getType().isPrimitive())
        	{
            	setNestedObject(targetObject, fieldName, value);
            }
        }
        else
        {
            doSet(targetObject, value);
        }
    }


   * the second modification i did is needed because the test on the 'set'
method
     works only for primitive types. But if we store a Date for example in a
nested
     object, it will be nevertheless created. But the test can not extend
the test
     made earlier, because if we nested objects could have non-null default
values
     for certain fields.  So i overrided the 'setNestedObject' method to
perform
     the test so that when realizing that the nested object is null, there
is no need
     to create one to put a null value in the field.
     When the added test 'if (attrib != null || value != null)' is true
     the instanciation and setting of the attribute is skipped.

    protected void setNestedObject(Object obj, String fieldName, Object
value)
    {
        int index = fieldName.indexOf(PATH_TOKEN);
        if (index >= 0)
        {
            String name = fieldName.substring(0, index);
            PersistentField pField =
createInternPersistentField(ProxyHelper.getRealClass(obj), name);
            Object attrib = pField.get(ProxyHelper.getRealObject(obj));
            if (attrib != null || value != null)
            {
                  if (attrib == null)
                  {
                    .......
	            }
	            String nestedName = fieldName.substring(index +
PATH_TOKEN.length());
	            setNestedObject(attrib, nestedName, value);
	        }
        }
        else
        {
            PersistentField pField =
createInternPersistentField(ProxyHelper.getRealClass(obj), fieldName);
            pField.set(ProxyHelper.getRealObject(obj), value);
        }

    }

Best regards,

Guillaume Nodet





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


Problem with foreign keys in cvs lastest version

Posted by Guillaume Nodet <gu...@deliasystems.com>.
I've got an exception that is thrown when using the lastest version of ojb
in cvs
that did not occured with the labelled RC5. I'm not using batch mode for
this problem:

Caused by: org.apache.ojb.broker.KeyConstraintViolatedException: SQL failure
while insert object data for class com.opti
time.api.datamodel.entity.Unavailability, PK of the given object is [
ida=19], object was com.optitime.api.datamodel.ent
ity.Unavailability@c84051, exception message is [Integrity constraint
violation - no parent UNAVAILABILITIES_FK_4 table:
 RESOURCEPROPERTIES in statement [INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,o
pt_beginday,opt_endday,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,res
unavailabilities,actunavailabilities,depunav
ailabilities,propunavailabilities,rsvpunavailabilities) VALUES
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ]]: Integrity constrain
t violation - no parent UNAVAILABILITIES_FK_4 table: RESOURCEPROPERTIES in
statement [INSERT INTO unavailabilities (ida,
opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_endday,o
pt_cardid,opt_code,opt_boundsbegin,opt_bound
send,resunavailabilities,actunavailabilities,depunavailabilities,propunavail
abilities,rsvpunavailabilities) VALUES (?,?,
?,?,?,?,?,?,?,?,?,?,?,?,?,?) ]
        at
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeInsert(Unknown
Source)
        at
org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(Unknown Source)
        at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown
Source)
        at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown
Source)
        at
org.apache.ojb.broker.core.PersistenceBrokerImpl.storeCollections(Unknown
Source)
        at
org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(Unknown Source)
        at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown
Source)
        at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown
Source)
        at
org.apache.ojb.broker.core.PersistenceBrokerImpl.storeCollections(Unknown
Source)
        at
org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(Unknown Source)
        at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown
Source)
        at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown
Source)
        at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(Unknown Source)
        at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(Unknown Source)
        at
com.optitime.synchronizer6.Synchronizer.mapObjectIntoTables(Synchronizer.jav
a:942)
        ... 2 more


Here are the p6spy log purged:

INSERT INTO resources
(id,opt_name,opt_cardid,opt_domainid,opt_classname,opt_projectid,opt_agendai
d,opt_capacity,opt_capacitytype,opt_allocationminduration,opt_allocationstep
,opt_vehicle,opt_modifydatestampclientid,opt_modifydatestampclientname,opt_m
odifydatestampdate,opt_modifydatestampcounter,opt_dependencyids) VALUES
('172974','BEAUVAIS
Michel','172975','42','Inspecteur','0','0','-1','1','-1','-1','0','51','sud'
,'2003-09-03','0','#NULL#')
INSERT INTO properties
(ida,opt_name,opt_appname,opt_valuetype,opt_value,resdata,actdata,prjdata,ca
rdproperties,sitedata,depdata,agndata,secdata,matdata,rsvdata) VALUES
('2146','API_DATA','','1','<<OptiTime>>;<<OPT=1>>;','172974','','','','','',
'','','','')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('1','Habilitation','1','CRECEP_DEFECT','')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('2','Habilitation','1','RECH_PT_PRELEV','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('3','Habilitation','1','INTER_DIVERS','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('4','Habilitation','1','OS_SADE','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('5','Habilitation','1','ADM_DIVERS','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('6','Habilitation','1','CONGE','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('7','Habilitation','1','CN','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('8','Habilitation','1','OF','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('9','Habilitation','1','AE_A_PROGRAM','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('10','Habilitation','1','AE_A_FAIRE','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('11','Habilitation','1','BRT_RV','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('12','Habilitation','1','BRT_PV_TRX','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('13','Habilitation','1','REPRISE_ABNT','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('14','Habilitation','1','TRX_APRES_CR','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('15','Habilitation','1','SUIVI_CONCESS','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('16','Habilitation','1','FUITE','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('17','Habilitation','1','SUIVI_SADE','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('18','Habilitation','1','OV','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('19','Habilitation','1','SARP_A_VERIFIER','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('20','Habilitation','1','SARP_SUIVI','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('21','Habilitation','1','RENS_PROJET_CANA','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('22','Habilitation','1','VERIF_BI_PI','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('23','Habilitation','1','INTERV_PROD','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('24','Habilitation','1','INTERV_RESEAU','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('25','Habilitation','1','SIG','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('26','Habilitation','1','INTERCOM','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('27','Habilitation','1','RQE','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('28','Habilitation','1','CL_TURBI_HEBDO','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('29','Habilitation','1','QE_PONCTUELLE','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('30','Habilitation','1','DESINF_CANALO','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('31','Habilitation','1','RINCAGE_APRES_DESINF','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('32','Habilitation','1','PRELEV_APRES_DESINF','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('33','Habilitation','1','RINCAGE_PONCTUEL','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('34','DI_Categorie','1','Differable','172974')
INSERT INTO resourceproperties
(ida,opt_name,opt_valuetype,opt_value,resproperties) VALUES
('35','DI_Categorie','1','Non differable','172974')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('1','3','1','00:00:00','13:00:00','4','4','0','0','2003-08-28','2003-08-29'
,'','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('2','3','1','00:00:00','13:00:00','3','3','0','0','2003-08-27','2003-08-28'
,'','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('3','3','1','00:00:00','13:00:00','2','2','0','0','2003-08-26','2003-08-27'
,'','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('4','3','1','00:00:00','13:00:00','1','1','0','0','2003-08-25','2003-08-26'
,'','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('5','3','1','00:00:00','13:00:00','7','7','0','0','2003-08-24','2003-08-25'
,'','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('6','3','1','00:00:00','13:00:00','6','6','0','0','2003-08-23','2003-08-24'
,'','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('7','3','1','00:00:00','13:00:00','5','5','0','0','2003-08-22','2003-08-23'
,'','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('8','3','1','00:00:00','13:00:00','4','4','0','0','2003-08-14','2003-08-15'
,'','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('9','3','1','00:00:00','13:00:00','3','3','0','0','2003-08-13','2003-08-14'
,'','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('10','3','1','00:00:00','13:00:00','2','2','0','0','2003-08-12','2003-08-13
','','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('11','3','1','00:00:00','13:00:00','1','1','0','0','2003-08-11','2003-08-12
','','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('12','3','1','00:00:00','13:00:00','7','7','0','0','2003-08-10','2003-08-11
','','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('13','3','1','00:00:00','13:00:00','6','6','0','0','2003-08-09','2003-08-10
','','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('14','3','1','00:00:00','13:00:00','5','5','0','0','2003-08-08','2003-08-09
','','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('15','3','1','00:00:00','13:00:00','4','4','0','0','2003-07-24','2003-07-25
','','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('16','3','1','00:00:00','13:00:00','3','3','0','0','2003-07-23','2003-07-24
','','','','35','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('18','3','1','00:00:00','13:00:00','2','2','0','0','2003-07-22','2003-07-23
','','','','','')
INSERT INTO unavailabilities
(ida,opt_type,opt_periodicity,opt_begintime,opt_endtime,opt_beginday,opt_end
day,opt_cardid,opt_code,opt_boundsbegin,opt_boundsend,resunavailabilities,ac
tunavailabilities,depunavailabilities,propunavailabilities,rsvpunavailabilit
ies) VALUES
('19','3','1','00:00:00','13:00:00','1','1','0','0','2003-07-21','2003-07-22
','','','','36','')



The problem is that considering the object model, the two last inserts
statements should have been executed with a foreign-key index of '35' and
not '' and '36'.


Guillaume



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


Re: AW: AW: AW: AW: Two 1:N mappings to one table

Posted by Brian McCallister <mc...@forthillcompany.com>.
No! You misunderstood me.

Declare the PK's, FK's etc in the database. Do not abandon good  
database practices for OJB -- particularly as never know what programs  
will access the DB directly in the future.

The DB managed auto-increment is the thing that is causing OJB to  
hiccup on you, I suspect. If you do an insert specifying the PK will  
DB2 override your specified one and replace it with its generated one,  
or will it accept your specified one?

A good description of the High-Low sequence algorithm is in the  
SDMagazine issue ( http://www.sdmagazine.com/articles/1999/9912/ ) but  
it is non free. You can google for other examples =) It is an efficient  
algorithm for managing sequences, basically.

If you have some values inserted by OJB's hi-low implementation, and  
some by the database using auto-generation you risk a collision. If you  
need the database auto-generation of keys (for batch inserts via a  
different tool, or other applications for example) having the database  
pull values from a database sequence that you also have OJB pull values  
from for OJB auto increment fields is the most reliable way to do this.

http://db.apache.org/ojb/api/org/apache/ojb/broker/util/sequence/ 
SequenceManagerNextValImpl.html

Is the base implementation for OJB that works (I am told, I don't use  
DB2) with DB2 sequences.

-Brian

On Jan 15, 2004, at 11:42 AM, Dirk Manske (Service Respond) wrote:

> hm. our db2 database tables are configured with an autoincrement for  
> the
> primary keys by default. (for exampl: activityId INTEGER NOT NULL  
> GENERATED
> BY DEFAULT AS IDENTITY (STARTS WITH 1, INCREMENT BY 1, NO CACHE,  
> PRIMARY
> KEY).  this is my first time using ojb. Meanwhile I get aware of what  
> ojb
> can all do for me. In the repository-user.xml I set every pk column  
> with
> primarykey="true" and autoincrement="true" for "declarative reasons",
> because I thought OJB must get to know which columns in db2 are set to
> pk's... Now I am wondering if the best practice would be to set up the
> physical database with no pk's, fk's etc at all and declare everything  
> in
> the repository and let ojb control it?
>
> Furthermore I  already declared a high/low sequence manager in the
> repository without actually knowing what I was doing (I copied it from
> somewhere). So please could you tell me what happend behind the  
> scenes? I
> guess OJB generated an id and tried to store it with the object but  
> then,
> db2 overwrote the id via autoincrement. After the second store  
> operation,
> OJB looks for its generated id, cannot find it and stores it as a new
> activity instead of updating it. hm. what would be the best advised? I
> haven't asked yet but I am pretty sure that I am not allowed to set
> autoincrement off in db2, because other apps might use these tables as
> well...
>
> -----Ursprüngliche Nachricht-----
> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
> Gesendet: Donnerstag, 15. Januar 2004 16:44
> An: OJB Users List
> Betreff: Re: AW: AW: AW: Two 1:N mappings to one table
>
> Ah hah! You are allowing DB2 to add the ID via a trigger, aren't you?
> OJB doesn't play super nicely with the database doing that for it  
> behind the
> scenes, unfortunately. If you are allowed, try using one of the OJB  
> auto
> increment modules. I suggest the one that pulls from a db sequence if  
> that
> is what you are using in DB2 now. Basically it will have OJB pull from  
> the
> sequence and populate the id prior to the insert so that OJB knows the  
> id.
>
> -Brian
>
> On Jan 15, 2004, at 10:25 AM, Dirk Manske (Service Respond) wrote:
>
>> Unfortunately I cannot provide a testcase for this. But in general,
>> after I stored the activity with pm.store(venture), the second
>> operation
>> pm.store(person) should automagically update activity and not save it
>> as a new entry, right? Or will it be only updated, if the activityId
>> is known?
>> Because I use DB2 with autoincrement for pk's and therefore on the
>> first store operation I have no id yet. hm. any idea?
>>
>> Dirk
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>> Gesendet: Donnerstag, 15. Januar 2004 04:28
>> An: OJB Users List
>> Betreff: Re: AW: AW: Two 1:N mappings to one table
>>
>> Hmm, fun one. I suspect you may have run into the weird edge case.
>>
>> I don't have an immediate answer on this -- need to play and dig.
>>
>> Anyone else hit this before? Any chance you can create a unit test
>> that demonstrates the behavior? If so send it to me and I'll check it
>> in and dig in (or start prodding).
>>
>> -Brian
>>
>> On Jan 14, 2004, at 1:21 PM, Dirk Manske (Service Respond) wrote:
>>
>>> Hi Brian,
>>>
>>> exactly. Due to copy & paste I assigned a wrong column to the
>>> attribute activityId in class Person. But know I experience the
>>> problem, that each created activity is stored twice (with different
>>> id's). I mean, I know why, I add activity once to the 'person
>>> collection' and to the 'venture collection' and do then
>>> pm.store(venture) and pm.store(person). I guess I have to follow a
>>> different approach?! Say, store first venture, then retrieve activity
>>> to store it with person? or how does it work?
>>>
>>> thx,
>>> Dirk
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>> Gesendet: Mittwoch, 14. Januar 2004 18:33
>>> An: OJB Users List
>>> Betreff: Re: AW: Two 1:N mappings to one table
>>>
>>> It sounds like there is actually a problem in the mapping from class
>>> -> table where the activityId is listed.
>>>
>>> Any chance you could post the full mapping for these classes, along
>>> with the database schema?
>>>
>>> -Brian
>>>
>>> On Jan 14, 2004, at 11:33 AM, Dirk Manske (Service Respond) wrote:
>>>
>>>> Hi,
>>>>
>>>> yes, i am using pb.  Setting auto-retrieve="true" in the
>>>> collection-descriptor has not the desired effect, I still get the
>>>> following two strange error messages:
>>>>
>>>> within browser it shows a null pointer execption for Venture when it
>>>> tried to retrieve all venture objects associated with activity and
>>>> in the tomcat console I get a SQL Exception for class PERSON, state
>>>> that activityId is not valid in the context where it is used (db2
>>>> database error message).
>>>>
>>>> When I set auto-retrieve="false" for PERSON in the
>>>> reference-descriptor of class ACTIVITY, the venture objects are
>>>> retrieved. no error message.
>>>> everything works fine, except - of course I have no person objects
>>>> then.
>>>>
>>>> any idea?
>>>>
>>>> Dirk
>>>>
>>>>
>>>>
>>>>
>>>> -----Ursprüngliche Nachricht-----
>>>> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>>> Gesendet: Mittwoch, 14. Januar 2004 15:13
>>>> An: OJB Users List
>>>> Betreff: Re: Two 1:N mappings to one table
>>>>
>>>> Mapping to 1:N's to the same table is fine, heack mapping 1:N's form
>>>> one class to itself multiple times works fine.
>>>>
>>>>  From looking at your configs I will venture that you are using the
>>>> PB API and one of the collections isn't loading -- try setting
>>>> auto-retrieve on the collections, or (these are exclusive) try using
>>>> the ODMG API (which will retrieve them automagically)
>>>>
>>>> -Brian
>>>>
>>>> On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> how can I map two tables with each having a 1:N relation to the
>>>>> same table?
>>>>> I always get a null pointer exception for class Person.
>>>>>
>>>>> I have three tables:
>>>>>
>>>>> PERSON with a 1:N relation to ACTIVITY
>>>>>
>>>>> and
>>>>>
>>>>> VENTURE with a 1:N relation to ACTIVITY
>>>>>
>>>>> Table PERSON and VENTURE both references activityId from table
>>>>> ACTIVITY. In the repository-user.xml for each table which relates
>>>>> to ACTIVITY the collection-descriptor is setup
>>>>>
>>>>> for table VENTURE:
>>>>>
>>>>> <collection-descriptor
>>>>> name="allAssignedActivities"
>>>>> element-class-ref="de.plato.Activity"
>>>>> orderBy="activityId"
>>>>> sort="DESC"
>>>>> auto-update="true" >
>>>>> <inverse-foreignkey field-ref="ventureId" />
>>>>> </collection-descriptor>
>>>>>
>>>>> and for table PERSON:
>>>>>
>>>>> <collection-descriptor
>>>>> name="allAssignedActivities"
>>>>> element-class-ref="de.plato.Activity"
>>>>> orderBy="activityId"
>>>>> sort="DESC"
>>>>> auto-update="true" >
>>>>> <inverse-foreignkey field-ref="personId" />
>>>>> </collection-descriptor>
>>>>>
>>>>> for ACTIVITY, both tables are referenced:
>>>>>
>>>>> <reference-descriptor name="person"> class-ref="de.plato.Person"
>>>>> refresh="true"
>>>>> auto-retrieve="true">
>>>>> <foreign-key field-ref="personId" />
>>>>>
>>>>> and
>>>>>
>>>>> <reference-descriptor name="venture"> class-ref="de.plato.Venture"
>>>>> refresh="true"
>>>>> auto-retrieve="true">
>>>>> <foreign-key field-ref="ventureId" />
>>>>>
>>>>> Unfortunately, this does not work. What do I have to do?
>>>>>
>>>>> thx,
>>>>> Dirk
>>>>>
>>>>>
>>>>> -------------------------------------------------------------------
>>>>> -
>>>>> - To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>> - To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>> - To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>



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


Re: AW: AW: AW: AW: AW: Two 1:N mappings to one table

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi again,

if you run into trouble, you maybe need to patch PlatformDB2Impl class, 
because there was a check in of a fix by Matthias Roth after rc5.

Index: PlatformDb2Impl.java
   ===================================================================
   RCS file: 
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDb2Impl.java,v
   retrieving revision 1.7
   retrieving revision 1.8
   diff -u -r1.7 -r1.8
   --- PlatformDb2Impl.java	9 Dec 2003 22:48:20 -0000	1.7
   +++ PlatformDb2Impl.java	19 Dec 2003 18:01:10 -0000	1.8
   @@ -98,9 +98,13 @@
        {
            return "drop sequence " + sequenceName;
        }
   -
   -    public String getLastInsertIdentityQuery(String tableName)
   -    {
   -        return "values IDENTITY_VAL_LOCAL() fetch first row only";
   -    }
   +
   +	public String getLastInsertIdentityQuery(String tableName)
   +	{
   +		// matthias.roth@impart.ch
   +		// the function is used by the 
org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl
   +		// this call must be made before commit the insert cammand, so you
   +		// must turn off autocommit by seting the useAutoCommit="2", "1" 
should work too
   +		return "select IDENTITY_VAL_LOCAL() from sysibm.sysdummy1";
   +	}
    }

regards,
Armin

Dirk Manske (Service Respond) wrote:

> thank you both. you helped me a lot in understanding ojb. I'll give it a
> try.
> 
> Dirk  
> 
> -----Ursprüngliche Nachricht-----
> Von: Armin Waibel [mailto:armin@code-au-lait.de] 
> Gesendet: Donnerstag, 15. Januar 2004 18:06
> An: OJB Users List
> Betreff: Re: AW: AW: AW: AW: Two 1:N mappings to one table
> 
> Hi Dirk,
> 
> if you use Identity columns from database you can't use the default
> SequenceManager (SequenceManagerHighLowImpl). Have a look in
> http://db.apache.org/ojb/sequencemanager.html#nativeSequenceManager
> 
>  > can all do for me. In the repository-user.xml I set every pk column with
> 
>>primarykey="true" and autoincrement="true" for "declarative reasons",
> 
> 
> When using SequenceManagerNativeImpl you have to set access="readonly" too.
> 
> regards,
> Armin
> 
> Dirk Manske (Service Respond) wrote:
> 
> 
>>hm. our db2 database tables are configured with an autoincrement for 
>>the primary keys by default. (for exampl: activityId INTEGER NOT NULL 
>>GENERATED BY DEFAULT AS IDENTITY (STARTS WITH 1, INCREMENT BY 1, NO 
>>CACHE, PRIMARY KEY).  this is my first time using ojb. Meanwhile I get 
>>aware of what ojb can all do for me. In the repository-user.xml I set 
>>every pk column with primarykey="true" and autoincrement="true" for 
>>"declarative reasons", because I thought OJB must get to know which 
>>columns in db2 are set to pk's... Now I am wondering if the best 
>>practice would be to set up the physical database with no pk's, fk's 
>>etc at all and declare everything in the repository and let ojb control
> 
> it?
> 
>>Furthermore I  already declared a high/low sequence manager in the 
>>repository without actually knowing what I was doing (I copied it from 
>>somewhere). So please could you tell me what happend behind the 
>>scenes? I guess OJB generated an id and tried to store it with the 
>>object but then,
>>db2 overwrote the id via autoincrement. After the second store 
>>operation, OJB looks for its generated id, cannot find it and stores 
>>it as a new activity instead of updating it. hm. what would be the 
>>best advised? I haven't asked yet but I am pretty sure that I am not 
>>allowed to set autoincrement off in db2, because other apps might use 
>>these tables as well...
>>
>>-----Ursprüngliche Nachricht-----
>>Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>Gesendet: Donnerstag, 15. Januar 2004 16:44
>>An: OJB Users List
>>Betreff: Re: AW: AW: AW: Two 1:N mappings to one table
>>
>>Ah hah! You are allowing DB2 to add the ID via a trigger, aren't you? 
>>OJB doesn't play super nicely with the database doing that for it 
>>behind the scenes, unfortunately. If you are allowed, try using one of 
>>the OJB auto increment modules. I suggest the one that pulls from a db 
>>sequence if that is what you are using in DB2 now. Basically it will 
>>have OJB pull from the sequence and populate the id prior to the insert so
> 
> that OJB knows the id.
> 
>>-Brian
>>
>>On Jan 15, 2004, at 10:25 AM, Dirk Manske (Service Respond) wrote:
>>
>>
>>
>>>Unfortunately I cannot provide a testcase for this. But in general, 
>>>after I stored the activity with pm.store(venture), the second 
>>>operation
>>>pm.store(person) should automagically update activity and not save it 
>>>as a new entry, right? Or will it be only updated, if the activityId 
>>>is known?
>>>Because I use DB2 with autoincrement for pk's and therefore on the 
>>>first store operation I have no id yet. hm. any idea?
>>>
>>>Dirk
>>>
>>>-----Ursprüngliche Nachricht-----
>>>Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>>Gesendet: Donnerstag, 15. Januar 2004 04:28
>>>An: OJB Users List
>>>Betreff: Re: AW: AW: Two 1:N mappings to one table
>>>
>>>Hmm, fun one. I suspect you may have run into the weird edge case.
>>>
>>>I don't have an immediate answer on this -- need to play and dig.
>>>
>>>Anyone else hit this before? Any chance you can create a unit test 
>>>that demonstrates the behavior? If so send it to me and I'll check it 
>>>in and dig in (or start prodding).
>>>
>>>-Brian
>>>
>>>On Jan 14, 2004, at 1:21 PM, Dirk Manske (Service Respond) wrote:
>>>
>>>
>>>
>>>>Hi Brian,
>>>>
>>>>exactly. Due to copy & paste I assigned a wrong column to the 
>>>>attribute activityId in class Person. But know I experience the 
>>>>problem, that each created activity is stored twice (with different 
>>>>id's). I mean, I know why, I add activity once to the 'person 
>>>>collection' and to the 'venture collection' and do then
>>>>pm.store(venture) and pm.store(person). I guess I have to follow a 
>>>>different approach?! Say, store first venture, then retrieve activity 
>>>>to store it with person? or how does it work?
>>>>
>>>>thx,
>>>>Dirk
>>>>
>>>>-----Ursprüngliche Nachricht-----
>>>>Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>>>Gesendet: Mittwoch, 14. Januar 2004 18:33
>>>>An: OJB Users List
>>>>Betreff: Re: AW: Two 1:N mappings to one table
>>>>
>>>>It sounds like there is actually a problem in the mapping from class
>>>>-> table where the activityId is listed.
>>>>
>>>>Any chance you could post the full mapping for these classes, along 
>>>>with the database schema?
>>>>
>>>>-Brian
>>>>
>>>>On Jan 14, 2004, at 11:33 AM, Dirk Manske (Service Respond) wrote:
>>>>
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>yes, i am using pb.  Setting auto-retrieve="true" in the 
>>>>>collection-descriptor has not the desired effect, I still get the 
>>>>>following two strange error messages:
>>>>>
>>>>>within browser it shows a null pointer execption for Venture when it 
>>>>>tried to retrieve all venture objects associated with activity and 
>>>>>in the tomcat console I get a SQL Exception for class PERSON, state 
>>>>>that activityId is not valid in the context where it is used (db2 
>>>>>database error message).
>>>>>
>>>>>When I set auto-retrieve="false" for PERSON in the 
>>>>>reference-descriptor of class ACTIVITY, the venture objects are 
>>>>>retrieved. no error message.
>>>>>everything works fine, except - of course I have no person objects 
>>>>>then.
>>>>>
>>>>>any idea?
>>>>>
>>>>>Dirk
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>-----Ursprüngliche Nachricht-----
>>>>>Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>>>>Gesendet: Mittwoch, 14. Januar 2004 15:13
>>>>>An: OJB Users List
>>>>>Betreff: Re: Two 1:N mappings to one table
>>>>>
>>>>>Mapping to 1:N's to the same table is fine, heack mapping 1:N's form 
>>>>>one class to itself multiple times works fine.
>>>>>
>>>>>>From looking at your configs I will venture that you are using the 
>>>>>PB API and one of the collections isn't loading -- try setting 
>>>>>auto-retrieve on the collections, or (these are exclusive) try using 
>>>>>the ODMG API (which will retrieve them automagically)
>>>>>
>>>>>-Brian
>>>>>
>>>>>On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:
>>>>>
>>>>>
>>>>>
>>>>>>Hi,
>>>>>>
>>>>>>how can I map two tables with each having a 1:N relation to the 
>>>>>>same table?
>>>>>>I always get a null pointer exception for class Person.
>>>>>>
>>>>>>I have three tables:
>>>>>>
>>>>>>PERSON with a 1:N relation to ACTIVITY
>>>>>>
>>>>>>and
>>>>>>
>>>>>>VENTURE with a 1:N relation to ACTIVITY
>>>>>>
>>>>>>Table PERSON and VENTURE both references activityId from table 
>>>>>>ACTIVITY. In the repository-user.xml for each table which relates 
>>>>>>to ACTIVITY the collection-descriptor is setup
>>>>>>
>>>>>>for table VENTURE:
>>>>>>
>>>>>><collection-descriptor
>>>>>>name="allAssignedActivities"
>>>>>>element-class-ref="de.plato.Activity"
>>>>>>orderBy="activityId"
>>>>>>sort="DESC"
>>>>>>auto-update="true" >
>>>>>><inverse-foreignkey field-ref="ventureId" /> 
>>>>>></collection-descriptor>
>>>>>>
>>>>>>and for table PERSON:
>>>>>>
>>>>>><collection-descriptor
>>>>>>name="allAssignedActivities"
>>>>>>element-class-ref="de.plato.Activity"
>>>>>>orderBy="activityId"
>>>>>>sort="DESC"
>>>>>>auto-update="true" >
>>>>>><inverse-foreignkey field-ref="personId" /> 
>>>>>></collection-descriptor>
>>>>>>
>>>>>>for ACTIVITY, both tables are referenced:
>>>>>>
>>>>>><reference-descriptor name="person"> class-ref="de.plato.Person"
>>>>>>refresh="true"
>>>>>>auto-retrieve="true">
>>>>>><foreign-key field-ref="personId" />
>>>>>>
>>>>>>and
>>>>>>
>>>>>><reference-descriptor name="venture"> class-ref="de.plato.Venture"
>>>>>>refresh="true"
>>>>>>auto-retrieve="true">
>>>>>><foreign-key field-ref="ventureId" />
>>>>>>
>>>>>>Unfortunately, this does not work. What do I have to do?
>>>>>>
>>>>>>thx,
>>>>>>Dirk
>>>>>>
>>>>>>
>>>>>>-------------------------------------------------------------------
>>>>>>-
>>>>>>- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>--------------------------------------------------------------------
>>>>>- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>>--------------------------------------------------------------------
>>>>>- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 



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


AW: AW: AW: AW: AW: Two 1:N mappings to one table

Posted by "Dirk Manske (Service Respond)" <se...@nexgo.de>.
thank you both. you helped me a lot in understanding ojb. I'll give it a
try.

Dirk  

-----Ursprüngliche Nachricht-----
Von: Armin Waibel [mailto:armin@code-au-lait.de] 
Gesendet: Donnerstag, 15. Januar 2004 18:06
An: OJB Users List
Betreff: Re: AW: AW: AW: AW: Two 1:N mappings to one table

Hi Dirk,

if you use Identity columns from database you can't use the default
SequenceManager (SequenceManagerHighLowImpl). Have a look in
http://db.apache.org/ojb/sequencemanager.html#nativeSequenceManager

 > can all do for me. In the repository-user.xml I set every pk column with
> primarykey="true" and autoincrement="true" for "declarative reasons",

When using SequenceManagerNativeImpl you have to set access="readonly" too.

regards,
Armin

Dirk Manske (Service Respond) wrote:

> hm. our db2 database tables are configured with an autoincrement for 
> the primary keys by default. (for exampl: activityId INTEGER NOT NULL 
> GENERATED BY DEFAULT AS IDENTITY (STARTS WITH 1, INCREMENT BY 1, NO 
> CACHE, PRIMARY KEY).  this is my first time using ojb. Meanwhile I get 
> aware of what ojb can all do for me. In the repository-user.xml I set 
> every pk column with primarykey="true" and autoincrement="true" for 
> "declarative reasons", because I thought OJB must get to know which 
> columns in db2 are set to pk's... Now I am wondering if the best 
> practice would be to set up the physical database with no pk's, fk's 
> etc at all and declare everything in the repository and let ojb control
it?
> 
> Furthermore I  already declared a high/low sequence manager in the 
> repository without actually knowing what I was doing (I copied it from 
> somewhere). So please could you tell me what happend behind the 
> scenes? I guess OJB generated an id and tried to store it with the 
> object but then,
> db2 overwrote the id via autoincrement. After the second store 
> operation, OJB looks for its generated id, cannot find it and stores 
> it as a new activity instead of updating it. hm. what would be the 
> best advised? I haven't asked yet but I am pretty sure that I am not 
> allowed to set autoincrement off in db2, because other apps might use 
> these tables as well...
> 
> -----Ursprüngliche Nachricht-----
> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
> Gesendet: Donnerstag, 15. Januar 2004 16:44
> An: OJB Users List
> Betreff: Re: AW: AW: AW: Two 1:N mappings to one table
> 
> Ah hah! You are allowing DB2 to add the ID via a trigger, aren't you? 
> OJB doesn't play super nicely with the database doing that for it 
> behind the scenes, unfortunately. If you are allowed, try using one of 
> the OJB auto increment modules. I suggest the one that pulls from a db 
> sequence if that is what you are using in DB2 now. Basically it will 
> have OJB pull from the sequence and populate the id prior to the insert so
that OJB knows the id.
> 
> -Brian
> 
> On Jan 15, 2004, at 10:25 AM, Dirk Manske (Service Respond) wrote:
> 
> 
>>Unfortunately I cannot provide a testcase for this. But in general, 
>>after I stored the activity with pm.store(venture), the second 
>>operation
>>pm.store(person) should automagically update activity and not save it 
>>as a new entry, right? Or will it be only updated, if the activityId 
>>is known?
>>Because I use DB2 with autoincrement for pk's and therefore on the 
>>first store operation I have no id yet. hm. any idea?
>>
>>Dirk
>>
>>-----Ursprüngliche Nachricht-----
>>Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>Gesendet: Donnerstag, 15. Januar 2004 04:28
>>An: OJB Users List
>>Betreff: Re: AW: AW: Two 1:N mappings to one table
>>
>>Hmm, fun one. I suspect you may have run into the weird edge case.
>>
>>I don't have an immediate answer on this -- need to play and dig.
>>
>>Anyone else hit this before? Any chance you can create a unit test 
>>that demonstrates the behavior? If so send it to me and I'll check it 
>>in and dig in (or start prodding).
>>
>>-Brian
>>
>>On Jan 14, 2004, at 1:21 PM, Dirk Manske (Service Respond) wrote:
>>
>>
>>>Hi Brian,
>>>
>>>exactly. Due to copy & paste I assigned a wrong column to the 
>>>attribute activityId in class Person. But know I experience the 
>>>problem, that each created activity is stored twice (with different 
>>>id's). I mean, I know why, I add activity once to the 'person 
>>>collection' and to the 'venture collection' and do then
>>>pm.store(venture) and pm.store(person). I guess I have to follow a 
>>>different approach?! Say, store first venture, then retrieve activity 
>>>to store it with person? or how does it work?
>>>
>>>thx,
>>>Dirk
>>>
>>>-----Ursprüngliche Nachricht-----
>>>Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>>Gesendet: Mittwoch, 14. Januar 2004 18:33
>>>An: OJB Users List
>>>Betreff: Re: AW: Two 1:N mappings to one table
>>>
>>>It sounds like there is actually a problem in the mapping from class
>>>-> table where the activityId is listed.
>>>
>>>Any chance you could post the full mapping for these classes, along 
>>>with the database schema?
>>>
>>>-Brian
>>>
>>>On Jan 14, 2004, at 11:33 AM, Dirk Manske (Service Respond) wrote:
>>>
>>>
>>>>Hi,
>>>>
>>>>yes, i am using pb.  Setting auto-retrieve="true" in the 
>>>>collection-descriptor has not the desired effect, I still get the 
>>>>following two strange error messages:
>>>>
>>>>within browser it shows a null pointer execption for Venture when it 
>>>>tried to retrieve all venture objects associated with activity and 
>>>>in the tomcat console I get a SQL Exception for class PERSON, state 
>>>>that activityId is not valid in the context where it is used (db2 
>>>>database error message).
>>>>
>>>>When I set auto-retrieve="false" for PERSON in the 
>>>>reference-descriptor of class ACTIVITY, the venture objects are 
>>>>retrieved. no error message.
>>>>everything works fine, except - of course I have no person objects 
>>>>then.
>>>>
>>>>any idea?
>>>>
>>>>Dirk
>>>>
>>>>
>>>>
>>>>
>>>>-----Ursprüngliche Nachricht-----
>>>>Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>>>Gesendet: Mittwoch, 14. Januar 2004 15:13
>>>>An: OJB Users List
>>>>Betreff: Re: Two 1:N mappings to one table
>>>>
>>>>Mapping to 1:N's to the same table is fine, heack mapping 1:N's form 
>>>>one class to itself multiple times works fine.
>>>>
>>>> From looking at your configs I will venture that you are using the 
>>>>PB API and one of the collections isn't loading -- try setting 
>>>>auto-retrieve on the collections, or (these are exclusive) try using 
>>>>the ODMG API (which will retrieve them automagically)
>>>>
>>>>-Brian
>>>>
>>>>On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>how can I map two tables with each having a 1:N relation to the 
>>>>>same table?
>>>>>I always get a null pointer exception for class Person.
>>>>>
>>>>>I have three tables:
>>>>>
>>>>>PERSON with a 1:N relation to ACTIVITY
>>>>>
>>>>>and
>>>>>
>>>>>VENTURE with a 1:N relation to ACTIVITY
>>>>>
>>>>>Table PERSON and VENTURE both references activityId from table 
>>>>>ACTIVITY. In the repository-user.xml for each table which relates 
>>>>>to ACTIVITY the collection-descriptor is setup
>>>>>
>>>>>for table VENTURE:
>>>>>
>>>>><collection-descriptor
>>>>>name="allAssignedActivities"
>>>>>element-class-ref="de.plato.Activity"
>>>>>orderBy="activityId"
>>>>>sort="DESC"
>>>>>auto-update="true" >
>>>>><inverse-foreignkey field-ref="ventureId" /> 
>>>>></collection-descriptor>
>>>>>
>>>>>and for table PERSON:
>>>>>
>>>>><collection-descriptor
>>>>>name="allAssignedActivities"
>>>>>element-class-ref="de.plato.Activity"
>>>>>orderBy="activityId"
>>>>>sort="DESC"
>>>>>auto-update="true" >
>>>>><inverse-foreignkey field-ref="personId" /> 
>>>>></collection-descriptor>
>>>>>
>>>>>for ACTIVITY, both tables are referenced:
>>>>>
>>>>><reference-descriptor name="person"> class-ref="de.plato.Person"
>>>>>refresh="true"
>>>>>auto-retrieve="true">
>>>>><foreign-key field-ref="personId" />
>>>>>
>>>>>and
>>>>>
>>>>><reference-descriptor name="venture"> class-ref="de.plato.Venture"
>>>>>refresh="true"
>>>>>auto-retrieve="true">
>>>>><foreign-key field-ref="ventureId" />
>>>>>
>>>>>Unfortunately, this does not work. What do I have to do?
>>>>>
>>>>>thx,
>>>>>Dirk
>>>>>
>>>>>
>>>>>-------------------------------------------------------------------
>>>>>-
>>>>>- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>--------------------------------------------------------------------
>>>>- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>>--------------------------------------------------------------------
>>>>- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 



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


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


Re: AW: AW: AW: AW: Two 1:N mappings to one table

Posted by Armin Waibel <ar...@code-au-lait.de>.
Hi Dirk,

if you use Identity columns from database you can't use the default 
SequenceManager (SequenceManagerHighLowImpl). Have a look in
http://db.apache.org/ojb/sequencemanager.html#nativeSequenceManager

 > can all do for me. In the repository-user.xml I set every pk column with
 > primarykey="true" and autoincrement="true" for "declarative reasons",

When using SequenceManagerNativeImpl you have to set access="readonly" too.

regards,
Armin

Dirk Manske (Service Respond) wrote:

> hm. our db2 database tables are configured with an autoincrement for the
> primary keys by default. (for exampl: activityId INTEGER NOT NULL GENERATED
> BY DEFAULT AS IDENTITY (STARTS WITH 1, INCREMENT BY 1, NO CACHE, PRIMARY
> KEY).  this is my first time using ojb. Meanwhile I get aware of what ojb
> can all do for me. In the repository-user.xml I set every pk column with
> primarykey="true" and autoincrement="true" for "declarative reasons",
> because I thought OJB must get to know which columns in db2 are set to
> pk's... Now I am wondering if the best practice would be to set up the
> physical database with no pk's, fk's etc at all and declare everything in
> the repository and let ojb control it? 
> 
> Furthermore I  already declared a high/low sequence manager in the
> repository without actually knowing what I was doing (I copied it from
> somewhere). So please could you tell me what happend behind the scenes? I
> guess OJB generated an id and tried to store it with the object but then,
> db2 overwrote the id via autoincrement. After the second store operation,
> OJB looks for its generated id, cannot find it and stores it as a new
> activity instead of updating it. hm. what would be the best advised? I
> haven't asked yet but I am pretty sure that I am not allowed to set
> autoincrement off in db2, because other apps might use these tables as
> well...
> 
> -----Ursprüngliche Nachricht-----
> Von: Brian McCallister [mailto:mccallister@forthillcompany.com] 
> Gesendet: Donnerstag, 15. Januar 2004 16:44
> An: OJB Users List
> Betreff: Re: AW: AW: AW: Two 1:N mappings to one table
> 
> Ah hah! You are allowing DB2 to add the ID via a trigger, aren't you? 
> OJB doesn't play super nicely with the database doing that for it behind the
> scenes, unfortunately. If you are allowed, try using one of the OJB auto
> increment modules. I suggest the one that pulls from a db sequence if that
> is what you are using in DB2 now. Basically it will have OJB pull from the
> sequence and populate the id prior to the insert so that OJB knows the id.
> 
> -Brian
> 
> On Jan 15, 2004, at 10:25 AM, Dirk Manske (Service Respond) wrote:
> 
> 
>>Unfortunately I cannot provide a testcase for this. But in general, 
>>after I stored the activity with pm.store(venture), the second 
>>operation
>>pm.store(person) should automagically update activity and not save it 
>>as a new entry, right? Or will it be only updated, if the activityId 
>>is known?
>>Because I use DB2 with autoincrement for pk's and therefore on the 
>>first store operation I have no id yet. hm. any idea?
>>
>>Dirk
>>
>>-----Ursprüngliche Nachricht-----
>>Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>Gesendet: Donnerstag, 15. Januar 2004 04:28
>>An: OJB Users List
>>Betreff: Re: AW: AW: Two 1:N mappings to one table
>>
>>Hmm, fun one. I suspect you may have run into the weird edge case.
>>
>>I don't have an immediate answer on this -- need to play and dig.
>>
>>Anyone else hit this before? Any chance you can create a unit test 
>>that demonstrates the behavior? If so send it to me and I'll check it 
>>in and dig in (or start prodding).
>>
>>-Brian
>>
>>On Jan 14, 2004, at 1:21 PM, Dirk Manske (Service Respond) wrote:
>>
>>
>>>Hi Brian,
>>>
>>>exactly. Due to copy & paste I assigned a wrong column to the 
>>>attribute activityId in class Person. But know I experience the 
>>>problem, that each created activity is stored twice (with different 
>>>id's). I mean, I know why, I add activity once to the 'person 
>>>collection' and to the 'venture collection' and do then
>>>pm.store(venture) and pm.store(person). I guess I have to follow a 
>>>different approach?! Say, store first venture, then retrieve activity 
>>>to store it with person? or how does it work?
>>>
>>>thx,
>>>Dirk
>>>
>>>-----Ursprüngliche Nachricht-----
>>>Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>>Gesendet: Mittwoch, 14. Januar 2004 18:33
>>>An: OJB Users List
>>>Betreff: Re: AW: Two 1:N mappings to one table
>>>
>>>It sounds like there is actually a problem in the mapping from class
>>>-> table where the activityId is listed.
>>>
>>>Any chance you could post the full mapping for these classes, along 
>>>with the database schema?
>>>
>>>-Brian
>>>
>>>On Jan 14, 2004, at 11:33 AM, Dirk Manske (Service Respond) wrote:
>>>
>>>
>>>>Hi,
>>>>
>>>>yes, i am using pb.  Setting auto-retrieve="true" in the 
>>>>collection-descriptor has not the desired effect, I still get the 
>>>>following two strange error messages:
>>>>
>>>>within browser it shows a null pointer execption for Venture when it 
>>>>tried to retrieve all venture objects associated with activity and 
>>>>in the tomcat console I get a SQL Exception for class PERSON, state 
>>>>that activityId is not valid in the context where it is used (db2 
>>>>database error message).
>>>>
>>>>When I set auto-retrieve="false" for PERSON in the 
>>>>reference-descriptor of class ACTIVITY, the venture objects are 
>>>>retrieved. no error message.
>>>>everything works fine, except - of course I have no person objects 
>>>>then.
>>>>
>>>>any idea?
>>>>
>>>>Dirk
>>>>
>>>>
>>>>
>>>>
>>>>-----Ursprüngliche Nachricht-----
>>>>Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>>>Gesendet: Mittwoch, 14. Januar 2004 15:13
>>>>An: OJB Users List
>>>>Betreff: Re: Two 1:N mappings to one table
>>>>
>>>>Mapping to 1:N's to the same table is fine, heack mapping 1:N's form 
>>>>one class to itself multiple times works fine.
>>>>
>>>> From looking at your configs I will venture that you are using the 
>>>>PB API and one of the collections isn't loading -- try setting 
>>>>auto-retrieve on the collections, or (these are exclusive) try using 
>>>>the ODMG API (which will retrieve them automagically)
>>>>
>>>>-Brian
>>>>
>>>>On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>>how can I map two tables with each having a 1:N relation to the 
>>>>>same table?
>>>>>I always get a null pointer exception for class Person.
>>>>>
>>>>>I have three tables:
>>>>>
>>>>>PERSON with a 1:N relation to ACTIVITY
>>>>>
>>>>>and
>>>>>
>>>>>VENTURE with a 1:N relation to ACTIVITY
>>>>>
>>>>>Table PERSON and VENTURE both references activityId from table 
>>>>>ACTIVITY. In the repository-user.xml for each table which relates 
>>>>>to ACTIVITY the collection-descriptor is setup
>>>>>
>>>>>for table VENTURE:
>>>>>
>>>>><collection-descriptor
>>>>>name="allAssignedActivities"
>>>>>element-class-ref="de.plato.Activity"
>>>>>orderBy="activityId"
>>>>>sort="DESC"
>>>>>auto-update="true" >
>>>>><inverse-foreignkey field-ref="ventureId" /> 
>>>>></collection-descriptor>
>>>>>
>>>>>and for table PERSON:
>>>>>
>>>>><collection-descriptor
>>>>>name="allAssignedActivities"
>>>>>element-class-ref="de.plato.Activity"
>>>>>orderBy="activityId"
>>>>>sort="DESC"
>>>>>auto-update="true" >
>>>>><inverse-foreignkey field-ref="personId" /> 
>>>>></collection-descriptor>
>>>>>
>>>>>for ACTIVITY, both tables are referenced:
>>>>>
>>>>><reference-descriptor name="person"> class-ref="de.plato.Person"
>>>>>refresh="true"
>>>>>auto-retrieve="true">
>>>>><foreign-key field-ref="personId" />
>>>>>
>>>>>and
>>>>>
>>>>><reference-descriptor name="venture"> class-ref="de.plato.Venture"
>>>>>refresh="true"
>>>>>auto-retrieve="true">
>>>>><foreign-key field-ref="ventureId" />
>>>>>
>>>>>Unfortunately, this does not work. What do I have to do?
>>>>>
>>>>>thx,
>>>>>Dirk
>>>>>
>>>>>
>>>>>-------------------------------------------------------------------
>>>>>-
>>>>>- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>--------------------------------------------------------------------
>>>>- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>>--------------------------------------------------------------------
>>>>- To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 



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


AW: AW: AW: AW: Two 1:N mappings to one table

Posted by "Dirk Manske (Service Respond)" <se...@nexgo.de>.
hm. our db2 database tables are configured with an autoincrement for the
primary keys by default. (for exampl: activityId INTEGER NOT NULL GENERATED
BY DEFAULT AS IDENTITY (STARTS WITH 1, INCREMENT BY 1, NO CACHE, PRIMARY
KEY).  this is my first time using ojb. Meanwhile I get aware of what ojb
can all do for me. In the repository-user.xml I set every pk column with
primarykey="true" and autoincrement="true" for "declarative reasons",
because I thought OJB must get to know which columns in db2 are set to
pk's... Now I am wondering if the best practice would be to set up the
physical database with no pk's, fk's etc at all and declare everything in
the repository and let ojb control it? 

Furthermore I  already declared a high/low sequence manager in the
repository without actually knowing what I was doing (I copied it from
somewhere). So please could you tell me what happend behind the scenes? I
guess OJB generated an id and tried to store it with the object but then,
db2 overwrote the id via autoincrement. After the second store operation,
OJB looks for its generated id, cannot find it and stores it as a new
activity instead of updating it. hm. what would be the best advised? I
haven't asked yet but I am pretty sure that I am not allowed to set
autoincrement off in db2, because other apps might use these tables as
well...

-----Ursprüngliche Nachricht-----
Von: Brian McCallister [mailto:mccallister@forthillcompany.com] 
Gesendet: Donnerstag, 15. Januar 2004 16:44
An: OJB Users List
Betreff: Re: AW: AW: AW: Two 1:N mappings to one table

Ah hah! You are allowing DB2 to add the ID via a trigger, aren't you? 
OJB doesn't play super nicely with the database doing that for it behind the
scenes, unfortunately. If you are allowed, try using one of the OJB auto
increment modules. I suggest the one that pulls from a db sequence if that
is what you are using in DB2 now. Basically it will have OJB pull from the
sequence and populate the id prior to the insert so that OJB knows the id.

-Brian

On Jan 15, 2004, at 10:25 AM, Dirk Manske (Service Respond) wrote:

> Unfortunately I cannot provide a testcase for this. But in general, 
> after I stored the activity with pm.store(venture), the second 
> operation
> pm.store(person) should automagically update activity and not save it 
> as a new entry, right? Or will it be only updated, if the activityId 
> is known?
> Because I use DB2 with autoincrement for pk's and therefore on the 
> first store operation I have no id yet. hm. any idea?
>
> Dirk
>
> -----Ursprüngliche Nachricht-----
> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
> Gesendet: Donnerstag, 15. Januar 2004 04:28
> An: OJB Users List
> Betreff: Re: AW: AW: Two 1:N mappings to one table
>
> Hmm, fun one. I suspect you may have run into the weird edge case.
>
> I don't have an immediate answer on this -- need to play and dig.
>
> Anyone else hit this before? Any chance you can create a unit test 
> that demonstrates the behavior? If so send it to me and I'll check it 
> in and dig in (or start prodding).
>
> -Brian
>
> On Jan 14, 2004, at 1:21 PM, Dirk Manske (Service Respond) wrote:
>
>> Hi Brian,
>>
>> exactly. Due to copy & paste I assigned a wrong column to the 
>> attribute activityId in class Person. But know I experience the 
>> problem, that each created activity is stored twice (with different 
>> id's). I mean, I know why, I add activity once to the 'person 
>> collection' and to the 'venture collection' and do then
>> pm.store(venture) and pm.store(person). I guess I have to follow a 
>> different approach?! Say, store first venture, then retrieve activity 
>> to store it with person? or how does it work?
>>
>> thx,
>> Dirk
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>> Gesendet: Mittwoch, 14. Januar 2004 18:33
>> An: OJB Users List
>> Betreff: Re: AW: Two 1:N mappings to one table
>>
>> It sounds like there is actually a problem in the mapping from class
>> -> table where the activityId is listed.
>>
>> Any chance you could post the full mapping for these classes, along 
>> with the database schema?
>>
>> -Brian
>>
>> On Jan 14, 2004, at 11:33 AM, Dirk Manske (Service Respond) wrote:
>>
>>> Hi,
>>>
>>> yes, i am using pb.  Setting auto-retrieve="true" in the 
>>> collection-descriptor has not the desired effect, I still get the 
>>> following two strange error messages:
>>>
>>> within browser it shows a null pointer execption for Venture when it 
>>> tried to retrieve all venture objects associated with activity and 
>>> in the tomcat console I get a SQL Exception for class PERSON, state 
>>> that activityId is not valid in the context where it is used (db2 
>>> database error message).
>>>
>>> When I set auto-retrieve="false" for PERSON in the 
>>> reference-descriptor of class ACTIVITY, the venture objects are 
>>> retrieved. no error message.
>>> everything works fine, except - of course I have no person objects 
>>> then.
>>>
>>> any idea?
>>>
>>> Dirk
>>>
>>>
>>>
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>> Gesendet: Mittwoch, 14. Januar 2004 15:13
>>> An: OJB Users List
>>> Betreff: Re: Two 1:N mappings to one table
>>>
>>> Mapping to 1:N's to the same table is fine, heack mapping 1:N's form 
>>> one class to itself multiple times works fine.
>>>
>>>  From looking at your configs I will venture that you are using the 
>>> PB API and one of the collections isn't loading -- try setting 
>>> auto-retrieve on the collections, or (these are exclusive) try using 
>>> the ODMG API (which will retrieve them automagically)
>>>
>>> -Brian
>>>
>>> On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:
>>>
>>>> Hi,
>>>>
>>>> how can I map two tables with each having a 1:N relation to the 
>>>> same table?
>>>> I always get a null pointer exception for class Person.
>>>>
>>>> I have three tables:
>>>>
>>>> PERSON with a 1:N relation to ACTIVITY
>>>>
>>>> and
>>>>
>>>> VENTURE with a 1:N relation to ACTIVITY
>>>>
>>>> Table PERSON and VENTURE both references activityId from table 
>>>> ACTIVITY. In the repository-user.xml for each table which relates 
>>>> to ACTIVITY the collection-descriptor is setup
>>>>
>>>> for table VENTURE:
>>>>
>>>> <collection-descriptor
>>>> name="allAssignedActivities"
>>>> element-class-ref="de.plato.Activity"
>>>> orderBy="activityId"
>>>> sort="DESC"
>>>> auto-update="true" >
>>>> <inverse-foreignkey field-ref="ventureId" /> 
>>>> </collection-descriptor>
>>>>
>>>> and for table PERSON:
>>>>
>>>> <collection-descriptor
>>>> name="allAssignedActivities"
>>>> element-class-ref="de.plato.Activity"
>>>> orderBy="activityId"
>>>> sort="DESC"
>>>> auto-update="true" >
>>>> <inverse-foreignkey field-ref="personId" /> 
>>>> </collection-descriptor>
>>>>
>>>> for ACTIVITY, both tables are referenced:
>>>>
>>>> <reference-descriptor name="person"> class-ref="de.plato.Person"
>>>> refresh="true"
>>>> auto-retrieve="true">
>>>> <foreign-key field-ref="personId" />
>>>>
>>>> and
>>>>
>>>> <reference-descriptor name="venture"> class-ref="de.plato.Venture"
>>>> refresh="true"
>>>> auto-retrieve="true">
>>>> <foreign-key field-ref="ventureId" />
>>>>
>>>> Unfortunately, this does not work. What do I have to do?
>>>>
>>>> thx,
>>>> Dirk
>>>>
>>>>
>>>> -------------------------------------------------------------------
>>>> -
>>>> - To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>



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


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


Re: AW: AW: AW: Two 1:N mappings to one table

Posted by Brian McCallister <mc...@forthillcompany.com>.
Ah hah! You are allowing DB2 to add the ID via a trigger, aren't you? 
OJB doesn't play super nicely with the database doing that for it 
behind the scenes, unfortunately. If you are allowed, try using one of 
the OJB auto increment modules. I suggest the one that pulls from a db 
sequence if that is what you are using in DB2 now. Basically it will 
have OJB pull from the sequence and populate the id prior to the insert 
so that OJB knows the id.

-Brian

On Jan 15, 2004, at 10:25 AM, Dirk Manske (Service Respond) wrote:

> Unfortunately I cannot provide a testcase for this. But in general, 
> after I
> stored the activity with pm.store(venture), the second operation
> pm.store(person) should automagically update activity and not save it 
> as a
> new entry, right? Or will it be only updated, if the activityId is 
> known?
> Because I use DB2 with autoincrement for pk's and therefore on the 
> first
> store operation I have no id yet. hm. any idea?
>
> Dirk
>
> -----Ursprüngliche Nachricht-----
> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
> Gesendet: Donnerstag, 15. Januar 2004 04:28
> An: OJB Users List
> Betreff: Re: AW: AW: Two 1:N mappings to one table
>
> Hmm, fun one. I suspect you may have run into the weird edge case.
>
> I don't have an immediate answer on this -- need to play and dig.
>
> Anyone else hit this before? Any chance you can create a unit test that
> demonstrates the behavior? If so send it to me and I'll check it in 
> and dig
> in (or start prodding).
>
> -Brian
>
> On Jan 14, 2004, at 1:21 PM, Dirk Manske (Service Respond) wrote:
>
>> Hi Brian,
>>
>> exactly. Due to copy & paste I assigned a wrong column to the
>> attribute activityId in class Person. But know I experience the
>> problem, that each created activity is stored twice (with different
>> id's). I mean, I know why, I add activity once to the 'person
>> collection' and to the 'venture collection' and do then
>> pm.store(venture) and pm.store(person). I guess I have to follow a
>> different approach?! Say, store first venture, then retrieve activity
>> to store it with person? or how does it work?
>>
>> thx,
>> Dirk
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>> Gesendet: Mittwoch, 14. Januar 2004 18:33
>> An: OJB Users List
>> Betreff: Re: AW: Two 1:N mappings to one table
>>
>> It sounds like there is actually a problem in the mapping from class
>> -> table where the activityId is listed.
>>
>> Any chance you could post the full mapping for these classes, along
>> with the database schema?
>>
>> -Brian
>>
>> On Jan 14, 2004, at 11:33 AM, Dirk Manske (Service Respond) wrote:
>>
>>> Hi,
>>>
>>> yes, i am using pb.  Setting auto-retrieve="true" in the
>>> collection-descriptor has not the desired effect, I still get the
>>> following two strange error messages:
>>>
>>> within browser it shows a null pointer execption for Venture when it
>>> tried to retrieve all venture objects associated with activity and in
>>> the tomcat console I get a SQL Exception for class PERSON, state that
>>> activityId is not valid in the context where it is used (db2 database
>>> error message).
>>>
>>> When I set auto-retrieve="false" for PERSON in the
>>> reference-descriptor of class ACTIVITY, the venture objects are
>>> retrieved. no error message.
>>> everything works fine, except - of course I have no person objects
>>> then.
>>>
>>> any idea?
>>>
>>> Dirk
>>>
>>>
>>>
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>>> Gesendet: Mittwoch, 14. Januar 2004 15:13
>>> An: OJB Users List
>>> Betreff: Re: Two 1:N mappings to one table
>>>
>>> Mapping to 1:N's to the same table is fine, heack mapping 1:N's form
>>> one class to itself multiple times works fine.
>>>
>>>  From looking at your configs I will venture that you are using the
>>> PB API and one of the collections isn't loading -- try setting
>>> auto-retrieve on the collections, or (these are exclusive) try using
>>> the ODMG API (which will retrieve them automagically)
>>>
>>> -Brian
>>>
>>> On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:
>>>
>>>> Hi,
>>>>
>>>> how can I map two tables with each having a 1:N relation to the same
>>>> table?
>>>> I always get a null pointer exception for class Person.
>>>>
>>>> I have three tables:
>>>>
>>>> PERSON with a 1:N relation to ACTIVITY
>>>>
>>>> and
>>>>
>>>> VENTURE with a 1:N relation to ACTIVITY
>>>>
>>>> Table PERSON and VENTURE both references activityId from table
>>>> ACTIVITY. In the repository-user.xml for each table which relates to
>>>> ACTIVITY the collection-descriptor is setup
>>>>
>>>> for table VENTURE:
>>>>
>>>> <collection-descriptor
>>>> name="allAssignedActivities"
>>>> element-class-ref="de.plato.Activity"
>>>> orderBy="activityId"
>>>> sort="DESC"
>>>> auto-update="true" >
>>>> <inverse-foreignkey field-ref="ventureId" />
>>>> </collection-descriptor>
>>>>
>>>> and for table PERSON:
>>>>
>>>> <collection-descriptor
>>>> name="allAssignedActivities"
>>>> element-class-ref="de.plato.Activity"
>>>> orderBy="activityId"
>>>> sort="DESC"
>>>> auto-update="true" >
>>>> <inverse-foreignkey field-ref="personId" /> </collection-descriptor>
>>>>
>>>> for ACTIVITY, both tables are referenced:
>>>>
>>>> <reference-descriptor name="person"> class-ref="de.plato.Person"
>>>> refresh="true"
>>>> auto-retrieve="true">
>>>> <foreign-key field-ref="personId" />
>>>>
>>>> and
>>>>
>>>> <reference-descriptor name="venture"> class-ref="de.plato.Venture"
>>>> refresh="true"
>>>> auto-retrieve="true">
>>>> <foreign-key field-ref="ventureId" />
>>>>
>>>> Unfortunately, this does not work. What do I have to do?
>>>>
>>>> thx,
>>>> Dirk
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>> - To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>



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


AW: AW: AW: Two 1:N mappings to one table

Posted by "Dirk Manske (Service Respond)" <se...@nexgo.de>.
Unfortunately I cannot provide a testcase for this. But in general, after I
stored the activity with pm.store(venture), the second operation
pm.store(person) should automagically update activity and not save it as a
new entry, right? Or will it be only updated, if the activityId is known?
Because I use DB2 with autoincrement for pk's and therefore on the first
store operation I have no id yet. hm. any idea?

Dirk 

-----Ursprüngliche Nachricht-----
Von: Brian McCallister [mailto:mccallister@forthillcompany.com] 
Gesendet: Donnerstag, 15. Januar 2004 04:28
An: OJB Users List
Betreff: Re: AW: AW: Two 1:N mappings to one table

Hmm, fun one. I suspect you may have run into the weird edge case.

I don't have an immediate answer on this -- need to play and dig.

Anyone else hit this before? Any chance you can create a unit test that
demonstrates the behavior? If so send it to me and I'll check it in and dig
in (or start prodding).

-Brian

On Jan 14, 2004, at 1:21 PM, Dirk Manske (Service Respond) wrote:

> Hi Brian,
>
> exactly. Due to copy & paste I assigned a wrong column to the 
> attribute activityId in class Person. But know I experience the 
> problem, that each created activity is stored twice (with different 
> id's). I mean, I know why, I add activity once to the 'person 
> collection' and to the 'venture collection' and do then 
> pm.store(venture) and pm.store(person). I guess I have to follow a 
> different approach?! Say, store first venture, then retrieve activity 
> to store it with person? or how does it work?
>
> thx,
> Dirk
>
> -----Ursprüngliche Nachricht-----
> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
> Gesendet: Mittwoch, 14. Januar 2004 18:33
> An: OJB Users List
> Betreff: Re: AW: Two 1:N mappings to one table
>
> It sounds like there is actually a problem in the mapping from class 
> -> table where the activityId is listed.
>
> Any chance you could post the full mapping for these classes, along 
> with the database schema?
>
> -Brian
>
> On Jan 14, 2004, at 11:33 AM, Dirk Manske (Service Respond) wrote:
>
>> Hi,
>>
>> yes, i am using pb.  Setting auto-retrieve="true" in the 
>> collection-descriptor has not the desired effect, I still get the 
>> following two strange error messages:
>>
>> within browser it shows a null pointer execption for Venture when it 
>> tried to retrieve all venture objects associated with activity and in 
>> the tomcat console I get a SQL Exception for class PERSON, state that 
>> activityId is not valid in the context where it is used (db2 database 
>> error message).
>>
>> When I set auto-retrieve="false" for PERSON in the 
>> reference-descriptor of class ACTIVITY, the venture objects are 
>> retrieved. no error message.
>> everything works fine, except - of course I have no person objects 
>> then.
>>
>> any idea?
>>
>> Dirk
>>
>>
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>> Gesendet: Mittwoch, 14. Januar 2004 15:13
>> An: OJB Users List
>> Betreff: Re: Two 1:N mappings to one table
>>
>> Mapping to 1:N's to the same table is fine, heack mapping 1:N's form 
>> one class to itself multiple times works fine.
>>
>>  From looking at your configs I will venture that you are using the 
>> PB API and one of the collections isn't loading -- try setting 
>> auto-retrieve on the collections, or (these are exclusive) try using 
>> the ODMG API (which will retrieve them automagically)
>>
>> -Brian
>>
>> On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:
>>
>>> Hi,
>>>
>>> how can I map two tables with each having a 1:N relation to the same 
>>> table?
>>> I always get a null pointer exception for class Person.
>>>
>>> I have three tables:
>>>
>>> PERSON with a 1:N relation to ACTIVITY
>>>
>>> and
>>>
>>> VENTURE with a 1:N relation to ACTIVITY
>>>
>>> Table PERSON and VENTURE both references activityId from table 
>>> ACTIVITY. In the repository-user.xml for each table which relates to 
>>> ACTIVITY the collection-descriptor is setup
>>>
>>> for table VENTURE:
>>>
>>> <collection-descriptor
>>> name="allAssignedActivities"
>>> element-class-ref="de.plato.Activity"
>>> orderBy="activityId"
>>> sort="DESC"
>>> auto-update="true" >
>>> <inverse-foreignkey field-ref="ventureId" /> 
>>> </collection-descriptor>
>>>
>>> and for table PERSON:
>>>
>>> <collection-descriptor
>>> name="allAssignedActivities"
>>> element-class-ref="de.plato.Activity"
>>> orderBy="activityId"
>>> sort="DESC"
>>> auto-update="true" >
>>> <inverse-foreignkey field-ref="personId" /> </collection-descriptor>
>>>
>>> for ACTIVITY, both tables are referenced:
>>>
>>> <reference-descriptor name="person"> class-ref="de.plato.Person"
>>> refresh="true"
>>> auto-retrieve="true">
>>> <foreign-key field-ref="personId" />
>>>
>>> and
>>>
>>> <reference-descriptor name="venture"> class-ref="de.plato.Venture"
>>> refresh="true"
>>> auto-retrieve="true">
>>> <foreign-key field-ref="ventureId" />
>>>
>>> Unfortunately, this does not work. What do I have to do?
>>>
>>> thx,
>>> Dirk
>>>
>>>
>>> --------------------------------------------------------------------
>>> - To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>



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


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


Re: AW: AW: Two 1:N mappings to one table

Posted by Brian McCallister <mc...@forthillcompany.com>.
Hmm, fun one. I suspect you may have run into the weird edge case.

I don't have an immediate answer on this -- need to play and dig.

Anyone else hit this before? Any chance you can create a unit test that 
demonstrates the behavior? If so send it to me and I'll check it in and 
dig in (or start prodding).

-Brian

On Jan 14, 2004, at 1:21 PM, Dirk Manske (Service Respond) wrote:

> Hi Brian,
>
> exactly. Due to copy & paste I assigned a wrong column to the attribute
> activityId in class Person. But know I experience the problem, that 
> each
> created activity is stored twice (with different id's). I mean, I know 
> why,
> I add activity once to the 'person collection' and to the 'venture
> collection' and do then pm.store(venture) and pm.store(person). I 
> guess I
> have to follow a different approach?! Say, store first venture, then
> retrieve activity to store it with person? or how does it work?
>
> thx,
> Dirk
>
> -----Ursprüngliche Nachricht-----
> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
> Gesendet: Mittwoch, 14. Januar 2004 18:33
> An: OJB Users List
> Betreff: Re: AW: Two 1:N mappings to one table
>
> It sounds like there is actually a problem in the mapping from class ->
> table where the activityId is listed.
>
> Any chance you could post the full mapping for these classes, along 
> with the
> database schema?
>
> -Brian
>
> On Jan 14, 2004, at 11:33 AM, Dirk Manske (Service Respond) wrote:
>
>> Hi,
>>
>> yes, i am using pb.  Setting auto-retrieve="true" in the
>> collection-descriptor has not the desired effect, I still get the
>> following two strange error messages:
>>
>> within browser it shows a null pointer execption for Venture when it
>> tried to retrieve all venture objects associated with activity and in
>> the tomcat console I get a SQL Exception for class PERSON, state that
>> activityId is not valid in the context where it is used (db2 database
>> error message).
>>
>> When I set auto-retrieve="false" for PERSON in the
>> reference-descriptor of class ACTIVITY, the venture objects are
>> retrieved. no error message.
>> everything works fine, except - of course I have no person objects
>> then.
>>
>> any idea?
>>
>> Dirk
>>
>>
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
>> Gesendet: Mittwoch, 14. Januar 2004 15:13
>> An: OJB Users List
>> Betreff: Re: Two 1:N mappings to one table
>>
>> Mapping to 1:N's to the same table is fine, heack mapping 1:N's form
>> one class to itself multiple times works fine.
>>
>>  From looking at your configs I will venture that you are using the PB
>> API and one of the collections isn't loading -- try setting
>> auto-retrieve on the collections, or (these are exclusive) try using
>> the ODMG API (which will retrieve them automagically)
>>
>> -Brian
>>
>> On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:
>>
>>> Hi,
>>>
>>> how can I map two tables with each having a 1:N relation to the same
>>> table?
>>> I always get a null pointer exception for class Person.
>>>
>>> I have three tables:
>>>
>>> PERSON with a 1:N relation to ACTIVITY
>>>
>>> and
>>>
>>> VENTURE with a 1:N relation to ACTIVITY
>>>
>>> Table PERSON and VENTURE both references activityId from table
>>> ACTIVITY. In the repository-user.xml for each table which relates to
>>> ACTIVITY the collection-descriptor is setup
>>>
>>> for table VENTURE:
>>>
>>> <collection-descriptor
>>> name="allAssignedActivities"
>>> element-class-ref="de.plato.Activity"
>>> orderBy="activityId"
>>> sort="DESC"
>>> auto-update="true" >
>>> <inverse-foreignkey field-ref="ventureId" /> </collection-descriptor>
>>>
>>> and for table PERSON:
>>>
>>> <collection-descriptor
>>> name="allAssignedActivities"
>>> element-class-ref="de.plato.Activity"
>>> orderBy="activityId"
>>> sort="DESC"
>>> auto-update="true" >
>>> <inverse-foreignkey field-ref="personId" /> </collection-descriptor>
>>>
>>> for ACTIVITY, both tables are referenced:
>>>
>>> <reference-descriptor name="person">
>>> class-ref="de.plato.Person"
>>> refresh="true"
>>> auto-retrieve="true">
>>> <foreign-key field-ref="personId" />
>>>
>>> and
>>>
>>> <reference-descriptor name="venture"> class-ref="de.plato.Venture"
>>> refresh="true"
>>> auto-retrieve="true">
>>> <foreign-key field-ref="ventureId" />
>>>
>>> Unfortunately, this does not work. What do I have to do?
>>>
>>> thx,
>>> Dirk
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>



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


AW: AW: Two 1:N mappings to one table

Posted by "Dirk Manske (Service Respond)" <se...@nexgo.de>.
Hi Brian,

exactly. Due to copy & paste I assigned a wrong column to the attribute
activityId in class Person. But know I experience the problem, that each
created activity is stored twice (with different id's). I mean, I know why,
I add activity once to the 'person collection' and to the 'venture
collection' and do then pm.store(venture) and pm.store(person). I guess I
have to follow a different approach?! Say, store first venture, then
retrieve activity to store it with person? or how does it work?

thx,
Dirk

-----Ursprüngliche Nachricht-----
Von: Brian McCallister [mailto:mccallister@forthillcompany.com] 
Gesendet: Mittwoch, 14. Januar 2004 18:33
An: OJB Users List
Betreff: Re: AW: Two 1:N mappings to one table

It sounds like there is actually a problem in the mapping from class ->
table where the activityId is listed.

Any chance you could post the full mapping for these classes, along with the
database schema?

-Brian

On Jan 14, 2004, at 11:33 AM, Dirk Manske (Service Respond) wrote:

> Hi,
>
> yes, i am using pb.  Setting auto-retrieve="true" in the 
> collection-descriptor has not the desired effect, I still get the 
> following two strange error messages:
>
> within browser it shows a null pointer execption for Venture when it 
> tried to retrieve all venture objects associated with activity and in 
> the tomcat console I get a SQL Exception for class PERSON, state that 
> activityId is not valid in the context where it is used (db2 database 
> error message).
>
> When I set auto-retrieve="false" for PERSON in the 
> reference-descriptor of class ACTIVITY, the venture objects are 
> retrieved. no error message.
> everything works fine, except - of course I have no person objects 
> then.
>
> any idea?
>
> Dirk
>
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
> Gesendet: Mittwoch, 14. Januar 2004 15:13
> An: OJB Users List
> Betreff: Re: Two 1:N mappings to one table
>
> Mapping to 1:N's to the same table is fine, heack mapping 1:N's form 
> one class to itself multiple times works fine.
>
>  From looking at your configs I will venture that you are using the PB 
> API and one of the collections isn't loading -- try setting 
> auto-retrieve on the collections, or (these are exclusive) try using 
> the ODMG API (which will retrieve them automagically)
>
> -Brian
>
> On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:
>
>> Hi,
>>
>> how can I map two tables with each having a 1:N relation to the same 
>> table?
>> I always get a null pointer exception for class Person.
>>
>> I have three tables:
>>
>> PERSON with a 1:N relation to ACTIVITY
>>
>> and
>>
>> VENTURE with a 1:N relation to ACTIVITY
>>
>> Table PERSON and VENTURE both references activityId from table 
>> ACTIVITY. In the repository-user.xml for each table which relates to 
>> ACTIVITY the collection-descriptor is setup
>>
>> for table VENTURE:
>>
>> <collection-descriptor
>> name="allAssignedActivities"
>> element-class-ref="de.plato.Activity"
>> orderBy="activityId"
>> sort="DESC"
>> auto-update="true" >
>> <inverse-foreignkey field-ref="ventureId" /> </collection-descriptor>
>>
>> and for table PERSON:
>>
>> <collection-descriptor
>> name="allAssignedActivities"
>> element-class-ref="de.plato.Activity"
>> orderBy="activityId"
>> sort="DESC"
>> auto-update="true" >
>> <inverse-foreignkey field-ref="personId" /> </collection-descriptor>
>>
>> for ACTIVITY, both tables are referenced:
>>
>> <reference-descriptor name="person">
>> class-ref="de.plato.Person"
>> refresh="true"
>> auto-retrieve="true">
>> <foreign-key field-ref="personId" />
>>
>> and
>>
>> <reference-descriptor name="venture"> class-ref="de.plato.Venture"
>> refresh="true"
>> auto-retrieve="true">
>> <foreign-key field-ref="ventureId" />
>>
>> Unfortunately, this does not work. What do I have to do?
>>
>> thx,
>> Dirk
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>



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


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


Re: AW: Two 1:N mappings to one table

Posted by Brian McCallister <mc...@forthillcompany.com>.
It sounds like there is actually a problem in the mapping from class -> 
table where the activityId is listed.

Any chance you could post the full mapping for these classes, along 
with the database schema?

-Brian

On Jan 14, 2004, at 11:33 AM, Dirk Manske (Service Respond) wrote:

> Hi,
>
> yes, i am using pb.  Setting auto-retrieve="true" in the
> collection-descriptor has not the desired effect, I still get the 
> following
> two strange error messages:
>
> within browser it shows a null pointer execption for Venture when it 
> tried
> to retrieve all venture objects associated with activity and in the 
> tomcat
> console I get a
> SQL Exception for class PERSON, state that activityId is not valid in 
> the
> context where it is used (db2 database error message).
>
> When I set auto-retrieve="false" for PERSON in the 
> reference-descriptor of
> class ACTIVITY, the venture objects are retrieved. no error message.
> everything works fine, except - of course I have no person objects 
> then.
>
> any idea?
>
> Dirk
>
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Brian McCallister [mailto:mccallister@forthillcompany.com]
> Gesendet: Mittwoch, 14. Januar 2004 15:13
> An: OJB Users List
> Betreff: Re: Two 1:N mappings to one table
>
> Mapping to 1:N's to the same table is fine, heack mapping 1:N's form 
> one
> class to itself multiple times works fine.
>
>  From looking at your configs I will venture that you are using the PB 
> API
> and one of the collections isn't loading -- try setting auto-retrieve 
> on the
> collections, or (these are exclusive) try using the ODMG API (which 
> will
> retrieve them automagically)
>
> -Brian
>
> On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:
>
>> Hi,
>>
>> how can I map two tables with each having a 1:N relation to the same
>> table?
>> I always get a null pointer exception for class Person.
>>
>> I have three tables:
>>
>> PERSON with a 1:N relation to ACTIVITY
>>
>> and
>>
>> VENTURE with a 1:N relation to ACTIVITY
>>
>> Table PERSON and VENTURE both references activityId from table
>> ACTIVITY. In the repository-user.xml for each table which relates to
>> ACTIVITY the collection-descriptor is setup
>>
>> for table VENTURE:
>>
>> <collection-descriptor
>> name="allAssignedActivities"
>> element-class-ref="de.plato.Activity"
>> orderBy="activityId"
>> sort="DESC"
>> auto-update="true" >
>> <inverse-foreignkey field-ref="ventureId" /> </collection-descriptor>
>>
>> and for table PERSON:
>>
>> <collection-descriptor
>> name="allAssignedActivities"
>> element-class-ref="de.plato.Activity"
>> orderBy="activityId"
>> sort="DESC"
>> auto-update="true" >
>> <inverse-foreignkey field-ref="personId" /> </collection-descriptor>
>>
>> for ACTIVITY, both tables are referenced:
>>
>> <reference-descriptor name="person">
>> class-ref="de.plato.Person"
>> refresh="true"
>> auto-retrieve="true">
>> <foreign-key field-ref="personId" />
>>
>> and
>>
>> <reference-descriptor name="venture">
>> class-ref="de.plato.Venture"
>> refresh="true"
>> auto-retrieve="true">
>> <foreign-key field-ref="ventureId" />
>>
>> Unfortunately, this does not work. What do I have to do?
>>
>> thx,
>> Dirk
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>



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


AW: Two 1:N mappings to one table

Posted by "Dirk Manske (Service Respond)" <se...@nexgo.de>.
Hi,

yes, i am using pb.  Setting auto-retrieve="true" in the
collection-descriptor has not the desired effect, I still get the following
two strange error messages:

within browser it shows a null pointer execption for Venture when it tried
to retrieve all venture objects associated with activity and in the tomcat
console I get a
SQL Exception for class PERSON, state that activityId is not valid in the
context where it is used (db2 database error message).

When I set auto-retrieve="false" for PERSON in the reference-descriptor of
class ACTIVITY, the venture objects are retrieved. no error message.
everything works fine, except - of course I have no person objects then.

any idea?

Dirk 




-----Ursprüngliche Nachricht-----
Von: Brian McCallister [mailto:mccallister@forthillcompany.com] 
Gesendet: Mittwoch, 14. Januar 2004 15:13
An: OJB Users List
Betreff: Re: Two 1:N mappings to one table

Mapping to 1:N's to the same table is fine, heack mapping 1:N's form one
class to itself multiple times works fine.

 From looking at your configs I will venture that you are using the PB API
and one of the collections isn't loading -- try setting auto-retrieve on the
collections, or (these are exclusive) try using the ODMG API (which will
retrieve them automagically)

-Brian

On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:

> Hi,
>
> how can I map two tables with each having a 1:N relation to the same 
> table?
> I always get a null pointer exception for class Person.
>
> I have three tables:
>
> PERSON with a 1:N relation to ACTIVITY
>
> and
>
> VENTURE with a 1:N relation to ACTIVITY
>
> Table PERSON and VENTURE both references activityId from table 
> ACTIVITY. In the repository-user.xml for each table which relates to 
> ACTIVITY the collection-descriptor is setup
>
> for table VENTURE:
>
> <collection-descriptor
> name="allAssignedActivities"
> element-class-ref="de.plato.Activity"
> orderBy="activityId"
> sort="DESC"
> auto-update="true" >
> <inverse-foreignkey field-ref="ventureId" /> </collection-descriptor>
>
> and for table PERSON:
>
> <collection-descriptor
> name="allAssignedActivities"
> element-class-ref="de.plato.Activity"
> orderBy="activityId"
> sort="DESC"
> auto-update="true" >
> <inverse-foreignkey field-ref="personId" /> </collection-descriptor>
>
> for ACTIVITY, both tables are referenced:
>
> <reference-descriptor name="person">
> class-ref="de.plato.Person"
> refresh="true"
> auto-retrieve="true">
> <foreign-key field-ref="personId" />
>
> and
>
> <reference-descriptor name="venture">
> class-ref="de.plato.Venture"
> refresh="true"
> auto-retrieve="true">
> <foreign-key field-ref="ventureId" />
>
> Unfortunately, this does not work. What do I have to do?
>
> thx,
> Dirk
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>



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


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


Re: Two 1:N mappings to one table

Posted by Brian McCallister <mc...@forthillcompany.com>.
Mapping to 1:N's to the same table is fine, heack mapping 1:N's form 
one class to itself multiple times works fine.

 From looking at your configs I will venture that you are using the PB 
API and one of the collections isn't loading -- try setting 
auto-retrieve on the collections, or (these are exclusive) try using 
the ODMG API (which will retrieve them automagically)

-Brian

On Jan 13, 2004, at 7:58 PM, Dirk Manske wrote:

> Hi,
>
> how can I map two tables with each having a 1:N relation to the same 
> table?
> I always get a null pointer exception for class Person.
>
> I have three tables:
>
> PERSON with a 1:N relation to ACTIVITY
>
> and
>
> VENTURE with a 1:N relation to ACTIVITY
>
> Table PERSON and VENTURE both references activityId from table 
> ACTIVITY. In
> the repository-user.xml for each table which relates to ACTIVITY the
> collection-descriptor is setup
>
> for table VENTURE:
>
> <collection-descriptor
> name="allAssignedActivities"
> element-class-ref="de.plato.Activity"
> orderBy="activityId"
> sort="DESC"
> auto-update="true" >
> <inverse-foreignkey field-ref="ventureId" />
> </collection-descriptor>
>
> and for table PERSON:
>
> <collection-descriptor
> name="allAssignedActivities"
> element-class-ref="de.plato.Activity"
> orderBy="activityId"
> sort="DESC"
> auto-update="true" >
> <inverse-foreignkey field-ref="personId" />
> </collection-descriptor>
>
> for ACTIVITY, both tables are referenced:
>
> <reference-descriptor name="person">
> class-ref="de.plato.Person"
> refresh="true"
> auto-retrieve="true">
> <foreign-key field-ref="personId" />
>
> and
>
> <reference-descriptor name="venture">
> class-ref="de.plato.Venture"
> refresh="true"
> auto-retrieve="true">
> <foreign-key field-ref="ventureId" />
>
> Unfortunately, this does not work. What do I have to do?
>
> thx,
> Dirk
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>



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