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

2004-01-15 Thread Armin Waibel
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 -	1.7
  +++ PlatformDb2Impl.java	19 Dec 2003 18:01:10 -	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)
  +	{
  +		// [EMAIL PROTECTED]
  +		// 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:[EMAIL PROTECTED] 
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:[EMAIL PROTECTED]
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:[EMAIL PROTECTED]
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

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

2004-01-15 Thread Dirk Manske (Service Respond)
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:[EMAIL PROTECTED] 
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:[EMAIL PROTECTED]
> 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:[EMAIL PROTECTED]
>>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:[EMAIL PROTECTED]
>>>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 d