1

I have been using the code below to generate my UUID and post it in the database :

 if (addData.getGeneratedDocId() == null || addData.getGeneratedDocId().equals("")) {
        //addData.setGeneratedDocId(uniqueID);
        addData.setGeneratedDocId(UUID.randomUUID().toString());
    }

The problem is when I deploy my websites in AWS hosting, things start to get worst, I am having duplicate UUID constantly, I have not face any issues while running in the Local Host, any clue? Thanks in advance :)

Rylan Howard
  • 53
  • 11
  • 3
    From [this post](https://stackoverflow.com/questions/2513573/how-good-is-javas-uuid-randomuuid) the odds of this happening are exceedingly low. Can you give us some more information on your code? – stdunbar Feb 12 '18 at 16:47
  • At first, i tried to use <%!String uniqueID = UID.randomUUID().toString();%> to assign my UUID , when i goes into debug mode , i notice that the UUID does not change , after that i changed it to the code above, any clue? Thanks i did set my generatedUUID to null everytime after use (Adding into DB) with this : addData.setGeneratedDocId(null); – Aaron Lee Herng Yue Feb 12 '18 at 16:48
  • 1
    And you're using `java.util.UUID`, correct? What operating system? I've generated 10's of millions of UUID's this way and used it as a unique column in a database and never had an issue. That's what is so strange. – stdunbar Feb 12 '18 at 16:59
  • Yes, i dont know why i am having this issue too, duplicated ids end up messing up other datas in my database. Sorry i am new to Aws , i have no clue what OS i am using , I am using EC2 Micro for Hosting in Elastic Beanstalk though. – Aaron Lee Herng Yue Feb 12 '18 at 17:04
  • It was working fine when i am debugging in Netbeans, but error occurs when i am deploying to AWS and testing from it. – Aaron Lee Herng Yue Feb 12 '18 at 17:04
  • 1
    My guess is that you’re using the same `addData` object to repeatedly add data. Your code, however, only calls `setGeneratedDocId` once. – VGR Feb 12 '18 at 18:49
  • I found that problem occurs when i did not Post the form , where i would be getting the previous generated UUID out of nowhere, any solution to let it not save the previous generated UUIDs? Thanks – Aaron Lee Herng Yue Feb 12 '18 at 20:06

0 Answers0