Home » Java » java – Strange and duplicated UUIDs are getting generated all the time-Exceptionshub

java – Strange and duplicated UUIDs are getting generated all the time-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

There is an reccuring issue with my Spring Boot application (using Oracle Java 8, Hibernate and Oracle DB).
I have following error in the logs:
WARN o.h.e.jdbc.spi.SqlExceptionHelper.logExceptions – SQL Error: 1, SQLState: 23000
ERROR o.h.e.jdbc.spi.SqlExceptionHelper.logExceptions – ORA-00001: unique constraint (MY_SCHEMA.SYS_C0057302) violated

This constraint (SYS_C0057302) is UUID being UNIQUE. (UUID VARCHAR2(32) NOT NULL UNIQUE)

I cannot provoke this behaviour running it locally (even with load tests) – locally on windows it looks fine, but on RHEL (where it is deployed) problem occurs all the time.

Note that I have dozen more entity classes which all have UUIDs, but only this class is generating such strange duplicates all the time.

No idea how to fix it. Cannot find root cause of this.

Examples of UUIDsand classes used below:

There is a bit of normal UUIDs at the start, but after some time strange and duplicated UUIDs are being created. On 2 different RHEL envs.

Examples of normal UUIDs:
0C34561DD75D422CAD652715DF6C6E75
0CB86A03945040B9886752CC07EB116E
0DAA1A3AF2B5438F8CB9489348A92223
0EAE079E621B4D2B8E8BE445F76B14C9
0FCF05797E7E40DE8D3A9D6A3B44AAE1
12DEBCAB53C94285A4C3FF32C5A0BF8E
132A877F404D44069F78D9B74DD4BDC9
1338A8CE09B14552B78CBAD640A3CF29
136310C44374412FB5B1B8FAF7E35330

Example of strange UUIDs generated by UUID.randomUUID() – 99% of UUIDs are like that, very similiar, with 3 as number that comes up a lot:
33333330333433363333333233333339
33333330333433363333333333333336
33333330333433363333333433333330
33333330333433363333333433333332
33333330333433363333333433333333
33333330333433363333333533333330
33333330333433363333333533333333
33333330333433363333333533333339
33333330333433363333333533343332
33333330333433363333333633333332
33333330333433363333333633333334
33333330333433363333333733333333
33333330333433363333333733343335
33333330333433363333333833333333
33333330333433363333333933333332

TaskEntity class:

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import ----DashboardTaskDto;
import ----SimpleUserDto;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.UUID;

@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "TASK")
@ToString
@EntityListeners(AuditingEntityListener.class)
@Slf4j
class TaskEntity {

    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TASK_SEQ")
    @SequenceGenerator(sequenceName = "TASK_SEQ", allocationSize = 1, name = "TASK_SEQ")
    @Id
    private Long id;

    @Column(name = "KKF")
    private String kkf;

    @EqualsAndHashCode.Include
    private UUID uuid = UUID.randomUUID();

    private String customerName;
    private String assignedUserName;
    private String assignedUserRole;
    private int dpd;
    private Boolean bgk;
    private String courtProceedings;
    private String name;
    private LocalDateTime dueDate;
    private LocalDateTime doneDate;
    private BigDecimal totalLiabilities;
    private Long issueActivityId;
    private String userId;

    @Enumerated(EnumType.STRING)
    private TaskStatus status;

    @CreatedDate
    private LocalDateTime created;

    @LastModifiedDate
    private LocalDateTime modified;

    @Builder
    public TaskEntity(String kkf, String customerName, String assignedUserName, String assignedUserRole, int dpd, Boolean bgk, String courtProceedings, String name, LocalDateTime dueDate, LocalDateTime doneDate, BigDecimal totalLiabilities, Long issueActivityId, String userId, TaskStatus status, LocalDateTime created, LocalDateTime modified) {
        this.kkf = kkf;
        this.customerName = customerName;
        this.assignedUserName = assignedUserName;
        this.assignedUserRole = assignedUserRole;
        this.dpd = dpd;
        this.bgk = bgk;
        this.courtProceedings = courtProceedings;
        this.name = name;
        this.dueDate = dueDate;
        this.doneDate = doneDate;
        this.totalLiabilities = totalLiabilities;
        this.issueActivityId = issueActivityId;
        this.userId = userId;
        this.status = status;
        this.created = created;
        this.modified = modified;
    }

Task repository class:

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.Repository;
import org.springframework.lang.Nullable;

import java.util.Optional;

interface TaskRepository extends Repository<TaskEntity, Long> {
    TaskEntity save(TaskEntity from);

    Optional<TaskEntity> findByIssueActivityId(Long id);

    Page<TaskEntity> findAll(@Nullable Specification<TaskEntity> spec, Pageable pageable);
}

TaskCreator used for entity creation/updates:

class TaskCreator {
   public TaskEntity from(IssueActivityEntity issueActivityEntity) {
       IssueEntity issue = issueActivityEntity.getIssue();
       CustomerEntity customer = issue.getCustomer();
       UserEntity user = issueActivityEntity.getUser();
       return TaskEntity.builder()
           .kkf(customer.getKkf())
           .customerName(customer.getCompanyName())
           .assignedUserName(user.getName())
           .assignedUserRole(user.getRole())
           .dpd(issue.retrieveMaxDpd())
           .bgk(customer.isBgk())
           .courtProceedings(customer.getCourtProceedings())
           .name(issueActivityEntity.getActivity().getStatus())
           .dueDate(issueActivityEntity.getDueDate())
           .doneDate(issueActivityEntity.getDoneDate())
           .totalLiabilities(customer.getTotalLiabilities())
           .issueActivityId(issueActivityEntity.getId())
           .status(issueActivityEntity.getStatus())
           .userId(user.getId())
           .build();
   }

   TaskEntity updateFrom(final TaskEntity task, final IssueActivityEntity ia) {
       IssueEntity issue = ia.getIssue();
       CustomerEntity customer = issue.getCustomer();
       UserEntity user = ia.getUser();
       task.setKkf(customer.getKkf());
       task.setCustomerName(customer.getCompanyName());
       task.setAssignedUserRole(user.getRole());
       task.setDpd(issue.retrieveMaxDpd());
       task.setBgk(customer.isBgk());
       task.setCourtProceedings(customer.getCourtProceedings());
       task.setName(ia.getActivity().getStatus());
       task.setDueDate(ia.getDueDate());
       task.setDoneDate(ia.getDoneDate());
       task.setTotalLiabilities(customer.getTotalLiabilities());
       task.setIssueActivityId(ia.getId());
       task.setStatus(ia.getStatus());
       task.setUserId(user.getId());
       return task;
   }
}


How to&Answers: