in my object sometimes I need to create Id by myself. How can i tell to JPA to not create ID if there is already one?
@Data
@Builder
@Entity
@Table(name = "steps")
@NoArgsConstructor
@AllArgsConstructor
@EntityListeners(AuditingEntityListener.class)
@SequenceGenerator(name = "seq_steps", sequenceName = "seq_steps", allocationSize = 1)
public class Step implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;
}
This is how I created a step object.
var uuid = UUID.fromString("7f173364-1ad9-4e45-94ab-788fb641edb5")
Step step = new Step();
step.setAction(excelAction.getActionName());
step.setAction(StepType.STEP.name());
step.setId(uuid);
step.setCreatedBy(userName);
step.setModifiedBy(userName);
step.setTeam(team);
stepRepository.save()
when I check database I see entity saved with different uuid. How can can I force JPA to use my uuid and do you think is it a good approach?