Re: hoe to generate primarykey using dbunit?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re: hoe to generate primarykey using dbunit?

George Dinwiddie
san84 wrote:
> hi,
> hello am a beginner to this dbunit framework.
> i need to insert some tuples from my xmlfile on to database using the
> dbunitframework.
> but i wann to genetate this primarykey from dbunitframework itself. so that
> i can avoid specifying de same on that  xml file.
> how can i use dbunit in this manner??
> suggest me plz

I've found that dbunit doesn't work very well unless you allow it to
insert the primary keys of the test data.  Otherwise it cannot find the

You don't say what database you're using.  If you're using Oracle and
want numeric primary keys, you can use a trigger and sequence to insert
them, but also allow dbunit to override the trigger.  See 
for this technique.

If you're using Microsoft SQLserver, I don't know anyway to override the
automatic primary keys.  You can, however, turn that off and run dbunit
once to insert your test data.  Then, after turning the primary key
generation back on, dbunit will still be able to update the records it
inserted.  This works until you add a new record to your dbunit test
data, and then you need to repeat the procedure.

  hope this helps,

   * George Dinwiddie *            
   Software Development          
   Consultant and Coach          

This email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
dbunit-user mailing list
[hidden email]