How to keep primary key value the same as in dataset

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to keep primary key value the same as in dataset

Trieu Nguyen
Hi All,

I use dbunit 2.4.8, oracle 10g to junit test my application. 
I have data set like this
<dataset>
    <LOGINUSER ID="10006" NAME="AAAA" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10007" NAME="BBBB" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10008" NAME="CCCC" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10009" NAME="DDDD" PASSWORD="123456"   EMAIL="NONE"/>
</dataset>

These records are insert well into database. But the strange thing is that the value of ID column in database isn't the same at the value in dataset. They increase automatically after each test.

My question is how to keep the value in database the same as the value in my dataset.

Thanks,



------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: How to keep primary key value the same as in dataset

John Hurst-2
Did you create the table yourself? Any chance that there might be a trigger on it, doing something funky with the data as they are loaded?

To test that, you could try an INSERT in sqlplus, see what you get that way.

I can't think of any reason why DbUnit would change the ID values, or why DbUnit would cause increasing values after each test. Sounds like a trigger+sequence to me.

Regards

John Hurst
Wellington, New Zealand

On Tue, Mar 29, 2011 at 10:34 PM, Nguyen Viet Trieu <[hidden email]> wrote:
Hi All,

I use dbunit 2.4.8, oracle 10g to junit test my application. 
I have data set like this
<dataset>
    <LOGINUSER ID="10006" NAME="AAAA" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10007" NAME="BBBB" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10008" NAME="CCCC" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10009" NAME="DDDD" PASSWORD="123456"   EMAIL="NONE"/>
</dataset>

These records are insert well into database. But the strange thing is that the value of ID column in database isn't the same at the value in dataset. They increase automatically after each test.

My question is how to keep the value in database the same as the value in my dataset.

Thanks,



------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: How to keep primary key value the same as in dataset

Trieu Nguyen
Hi Hurst,

You're right. When I disable the BI_<table-name>, the value of ID in my dataset is kept. As you know BI_<table-name> trigger is created to automatically populate the current sequence value into ID primary key. Are there any ways to keep the original ID value in dataset the same as ID in database and doesn't disable this trigger? 

Regards,
Trieu Nguyen 

--- Ngày Thứ 3, 29/03/11, John Hurst <[hidden email]> đã viết:

Từ: John Hurst <[hidden email]>
Chủ đề: Re: [dbunit-user] How to keep primary key value the same as in dataset
Đến: [hidden email]
Ngày: Thứ Ba, 29 tháng 3, 2011, 17:06

Did you create the table yourself? Any chance that there might be a trigger on it, doing something funky with the data as they are loaded?

To test that, you could try an INSERT in sqlplus, see what you get that way.

I can't think of any reason why DbUnit would change the ID values, or why DbUnit would cause increasing values after each test. Sounds like a trigger+sequence to me.

Regards

John Hurst
Wellington, New Zealand

On Tue, Mar 29, 2011 at 10:34 PM, Nguyen Viet Trieu <jvtrieu@...> wrote:
Hi All,

I use dbunit 2.4.8, oracle 10g to junit test my application. 
I have data set like this
<dataset>
    <LOGINUSER ID="10006" NAME="AAAA" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10007" NAME="BBBB" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10008" NAME="CCCC" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10009" NAME="DDDD" PASSWORD="123456"   EMAIL="NONE"/>
</dataset>

These records are insert well into database. But the strange thing is that the value of ID column in database isn't the same at the value in dataset. They increase automatically after each test.

My question is how to keep the value in database the same as the value in my dataset.

Thanks,



------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game

-----Thư đính kèm sau đây-----

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar

-----Thư đính kèm sau đây-----

_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user


------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: How to keep primary key value the same as in dataset

John Hurst-2
I suspect you'll need to disable the trigger if you want to get certain values of your own in that column (with DbUnit, for example).

Alternatively, sometimes it's possible to write tests that are not sensitive to the specific ID values that get inserted into a key column. Sometimes you can assert results using DbUnit and a SELECT query that might not list the ID column in the SELECT list, only in the ORDER BY.

Regards

John Hurst

On Wed, Mar 30, 2011 at 7:32 PM, Nguyen Viet Trieu <[hidden email]> wrote:
Hi Hurst,

You're right. When I disable the BI_<table-name>, the value of ID in my dataset is kept. As you know BI_<table-name> trigger is created to automatically populate the current sequence value into ID primary key. Are there any ways to keep the original ID value in dataset the same as ID in database and doesn't disable this trigger? 

Regards,
Trieu Nguyen 

--- Ngày Thứ 3, 29/03/11, John Hurst <[hidden email]> đã viết:

Từ: John Hurst <[hidden email]>
Chủ đề: Re: [dbunit-user] How to keep primary key value the same as in dataset
Đến: [hidden email]
Ngày: Thứ Ba, 29 tháng 3, 2011, 17:06


Did you create the table yourself? Any chance that there might be a trigger on it, doing something funky with the data as they are loaded?

To test that, you could try an INSERT in sqlplus, see what you get that way.

I can't think of any reason why DbUnit would change the ID values, or why DbUnit would cause increasing values after each test. Sounds like a trigger+sequence to me.

Regards

John Hurst
Wellington, New Zealand

On Tue, Mar 29, 2011 at 10:34 PM, Nguyen Viet Trieu <jvtrieu@...> wrote:
Hi All,

I use dbunit 2.4.8, oracle 10g to junit test my application. 
I have data set like this
<dataset>
    <LOGINUSER ID="10006" NAME="AAAA" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10007" NAME="BBBB" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10008" NAME="CCCC" PASSWORD="123456"   EMAIL="NONE"/>
    <LOGINUSER ID="10009" NAME="DDDD" PASSWORD="123456"   EMAIL="NONE"/>
</dataset>

These records are insert well into database. But the strange thing is that the value of ID column in database isn't the same at the value in dataset. They increase automatically after each test.

My question is how to keep the value in database the same as the value in my dataset.

Thanks,



------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game

-----Thư đính kèm sau đây-----


------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar

-----Thư đính kèm sau đây-----


_______________________________________________
dbunit-user mailing list
dbunit-user@...
https://lists.sourceforge.net/lists/listinfo/dbunit-user


------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user