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
data.

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
http://idiacomputing.com/moin/PrimaryKeyGeneration#head-bf8960bfd6672e3be60c75caa52e705263354513 
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

--
  ----------------------------------------------------------------------
   * George Dinwiddie *                      http://blog.gdinwiddie.com
   Software Development                    http://www.idiacomputing.com
   Consultant and Coach                    http://www.agilemaryland.org
  ----------------------------------------------------------------------


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user