In my Project i use table "exampletrail" its have one composite key one of the primary key is "entrytime(timestamp)" another one is "instanceid (integer) - AUTO INCREMENT".my issue is Autoincrement field instanceid created one duplicate value. i dont know whether if its possible or not? yes means "how?". I need clear clarification.
This is necessory and it can be maintain uniqueness. but sometime it can make duplicate so that we create instance id with auto increment (for composite). i want to know if its possible the auto increment create the duplicate.
If I were implementing this I would not use a composite key, since you already have a surrogate key in the auto increment field. If you need a unique index on those two fields, use a unique index. But life is usually easier in the long run if you use a simple surrogate key as primary key.
Like I said before: Auto increment can't create duplicates. You'll get the details of this if you read the MySQL documentation (which I'm not going to repeat here).
prasad guna wrote:
Take this scenario and answer me .because the duplicaton created in my table that's why i create the thread here.
Are you sure the duplicated value was not created by another process? Eg. if the next value would be 100 and the table already contained a row with value 100, it would appear as if the error was caused by the insert statement, while in fact the problem could be that someone inserted or updated a row outside of your application.
(I don't know MySQL, but I assume that is is possible to change value of an AUTO INCREMENT column.)
Thanks for reply only one process for inserting rows through hibernate. I find some where while using on auto increment as a part of composite it will create the duplicates because it's not violate the composite rules so it will not keep the uniqueness.but i dont know the exact reason for that.
I find some where while using on auto increment as a part of composite it will create the duplicates because it's not violate the composite rules so it will not keep the uniqueness.but i dont know the exact reason for that.
Like I said before, auto increment will not generate duplicates. I would examine what you are doing to cause this - are you assigning values to the auto increment field?
i give example for that below i give the sql query run and check that,
This was taken from my table.I Use Hibernate i am not assigning the values to autoincrement column.its generate automatically.above data "3901" is a duplicate why its created there.