My problem is following.
I’ve one entity:
<code>@NoArgsConstructor
@AllArgsConstructor
@Data
@Table(name = "mytable")
@Builder
@Entity
public class MyEntity {
@Id
@GeneratedValue
@UuidGenerator
@Column
private UUID id;
@Column
private String name;
@Column
private UUID parent;
}
</code>
<code>@NoArgsConstructor
@AllArgsConstructor
@Data
@Table(name = "mytable")
@Builder
@Entity
public class MyEntity {
@Id
@GeneratedValue
@UuidGenerator
@Column
private UUID id;
@Column
private String name;
@Column
private UUID parent;
}
</code>
@NoArgsConstructor
@AllArgsConstructor
@Data
@Table(name = "mytable")
@Builder
@Entity
public class MyEntity {
@Id
@GeneratedValue
@UuidGenerator
@Column
private UUID id;
@Column
private String name;
@Column
private UUID parent;
}
When I perform such operations:
<code>myPersistence.save(mainEntity);
myPersistence.save(secondEntity);
</code>
<code>myPersistence.save(mainEntity);
myPersistence.save(secondEntity);
</code>
myPersistence.save(mainEntity);
myPersistence.save(secondEntity);
where mainEntity has parent value set to null, and secondEntity has parent value set to UUID of first saved mainEntity.
During save of secondEntity, I’m getting:
<code>org.springframework.dao.DataIntegrityViolationException: could not execute statement [ERROR: insert or update on table "mytable" violates foreign key constraint "fk_mytable_parent".
It says that given parent value of secondEntity is not present, but it's -> I've checked using find operation.
I tried to perform saveAndFlush operation from spring data jpa, but it still doesn't work.
Thank you for the help.
</code>
<code>org.springframework.dao.DataIntegrityViolationException: could not execute statement [ERROR: insert or update on table "mytable" violates foreign key constraint "fk_mytable_parent".
It says that given parent value of secondEntity is not present, but it's -> I've checked using find operation.
I tried to perform saveAndFlush operation from spring data jpa, but it still doesn't work.
Thank you for the help.
</code>
org.springframework.dao.DataIntegrityViolationException: could not execute statement [ERROR: insert or update on table "mytable" violates foreign key constraint "fk_mytable_parent".
It says that given parent value of secondEntity is not present, but it's -> I've checked using find operation.
I tried to perform saveAndFlush operation from spring data jpa, but it still doesn't work.
Thank you for the help.