Re: [OJB-developers] ODMG transaction question
Brought to you by:
thma
From: Thomas M. <tho...@ho...> - 2002-01-03 10:36:22
|
Hi Matt, > Matt Goodall wrote: > > Hi, > > I have found something which I can only describe as strange, perhaps > there is a legitimate explanation or perhaps it's a bug. > > First of all, some example code ... > > Database schema: > > create table artist > ( > id int not null, > name varchar2(100), > primary key (id), > unique (name) > ) > Code: > > Transaction tx = odmg.newTransaction(); > tx.begin(); > > Artist artist = new Artist(); > artist.name = "xyz"; > tx.lock(artist, Transaction.WRITE); > tx.checkpoint(); > > OQLQuery query = odmg.newOQLQuery(); > query.create("select allArtists from ojbtest.Artist"); > Collection list = (Collection) query.execute(); > Iterator it = list.iterator(); > while(it.hasNext()) > { > artist = (Artist) it.next(); > System.out.println(artist); > } > > tx.commit(); > > The 1st time the code is run the checkpoint commits the artist to the > database, as expected, and the "select allArtists" query returns the > expected rows. > > The 2nd time through, the unique(name) constraint means that the > artist cannot be added but the checkpoint succeeds (!!!), the "select > allArtists" returns the same objects that were seen the 1st time and, > finally, an exception is thrown in tx.commit(). > > As a test I wrote almost the equivalent using the lower level OJB > interface and everything worked as expected i.e. an exception was > thrown as soon as I tried to add the same artist. > > Is this the correct behaviour or is it a bug? This is definitively a bug in .checkpoint() ! I assume that exceptions thrown from the lower level PersistenceBroker API are ignored or not handled correctly during .checkpoint(). > > I have to say, I'm not sure I'd ever use transactions like this, it > all came about through some test code which *always* aborted the > transaction. I didn't have the checkpoint() then either. The intention > was to leave the database intact after running the test which addded > data and then retrieved it again - I was just playing with the API > basically. > But even if it's no realistic scenario: OJB must handle it correctly!!! Thanks for you detailed report, it will help me to fix this thing quickly! --Thomas > Cheers, Matt > --- > Matt Goodall > Analyst Programmer, Strategic Systems Solutions > e: mat...@ss..., t: +44 113 3892645 > |