0

How to generate id when there are composite keys in entity spring boot, I have make composite primary key using IdClass but it don't go well when I try to insert generated value from Spring Boot

@Entity
@DynamicUpdate
@DynamicInsert
@Table(name = "tm_trx_flow")
@IdClass(TmTrxFlowSerializable.class)
public class TmTrxFlow {
    @Id
    @Column(name ="tm_trx_procedure_id")
    private Integer tmTrxProcedureId;
    
    @Id     
    @SequenceGenerator(name = "some_seq", sequenceName = "empid_seq")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "some_seq")
    @Column(name="tm_trx_flow_id")
    private Integer tmTrxFlowId;
    
}
Vy Do
  • 46,709
  • 59
  • 215
  • 313

1 Answers1

0

primary key (composite keys) cannot auto generated.

Vy Do
  • 46,709
  • 59
  • 215
  • 313
  • what is the best practice to get value for primary key from composite keys ? – Adam Abdullah Nov 18 '21 at 08:24
  • You can use `@EmbeddedId` https://www.baeldung.com/jpa-composite-primary-keys ; https://stackoverflow.com/questions/13032948/how-to-create-and-handle-composite-primary-key-in-jpa – Vy Do Nov 18 '21 at 08:43