Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Persistence framework - commit problem

matt
Active Contributor
0 Likes
851

I've a program that works like this, on a persistent object with a sequence number as part of the key.

1. Use query service (get_persistent_by_query) to get list of objects matching the key - except the sequence number

2. Add 1 to the max sequence number

3. Create a new record with the new sequence number (all other key fields the same).

4. Repeat (once) from step 1.

5. Commit work.

The problem is, that when I do step 1 for the second time, the query doesn't return my new record, so when I'm in step 3, I get an error that the record already exists. If I do this:

1. Use query service (get_persistent_by_query) to get list of objects matching the key - except the sequence number

2. Add 1 to the max sequence number

3. Create a new record with the new sequence number (all other key fields the same).

4. Commit work AND WAIT.

5. Repeat (once) from step 1.

Then it works fine.

The query service call I've embedded in a static method, that does not use any static attributes. I'd expect my first approaching (bundling the database inserts, then doing a commit) to work. Any ideas why it doesn't? And can it be made to work, as it is obviously more efficient to do just one COMMIT.

Thanks

matt

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
809

Hi Matt,

Did you try doing the same with [COMMIT WORK AND WAIT|http://help.sap.com/saphelp_nw04/helpdata/en/d2/7849b8bec911d4b2e80050dadfb92b/frameset.htm]. Maybe then it will collect all updates and do physical DB update at once.

I also remember such example in one book with encapsulating everything within one transaction. Can't find the reference now, but I will check during the weekend and will drop you a sample if I find it. So please don't close your post too early;)

Regards

Marcin

5 REPLIES 5
Read only

MarcinPciak
Active Contributor
0 Likes
810

Hi Matt,

Did you try doing the same with [COMMIT WORK AND WAIT|http://help.sap.com/saphelp_nw04/helpdata/en/d2/7849b8bec911d4b2e80050dadfb92b/frameset.htm]. Maybe then it will collect all updates and do physical DB update at once.

I also remember such example in one book with encapsulating everything within one transaction. Can't find the reference now, but I will check during the weekend and will drop you a sample if I find it. So please don't close your post too early;)

Regards

Marcin

Read only

matt
Active Contributor
0 Likes
809

That does shed some light, thanks. I await your reference hunting!

Read only

0 Likes
809

Hi Matt,

I've found this information http://help.sap.com/saphelp_nw2004s/helpdata/en/ce/586e42472adc54e10000000a155106/frameset.htm At the end there is this statement "When the result quantity of a query is determined, the changes that are made in the current transaction to persistent objects are not considered. The query is executed directly in the database." I would understand this as "If you will do any changes within current LUV I will ignore them since I'm reading directly from DB". If my understanding is correct then you can either use 2 commits or extend your class with static attribute like LAST_SEQUENCE_NUMBER - if it's empty read data from DB and set it, if it's set increase its value and use it.

Best regards

Marcin Cholewczuk

Read only

matt
Active Contributor
0 Likes
809

That statement does seem to cover it. As far as programming for it, I'll bundle the results into an internal table, and do the SETting in one loop through.

thanks

matt

Read only

0 Likes
809

Sorry Matt, couldn't find appropriate example:( Apparently I mixed that with business layer that someone has built atop services for persisent objects (like read , update , delete ). All I could find is [IF_OS_TRANSACTION_MANAGER and IF_OS_TRANSACTION|http://help.sap.com/saphelp_nw04/helpdata/en/fa/f23c18330411d5992100508b6b8b11/frameset.htm] concept which provide transaction service. This doesn't however seem to fit your requirement as you want to work with same table (persistent object) in every loop. As persistent objects don't have implicit DB commit, I would therefore propably stick to COMMIT WORK AND WAIT (way of bundling) which you said is working. Then using final COMMIT WORK should do the job.

Marcin's suggestion sounds as good solution too.

Regards

Marcin