set auto_incremented primary key explicitly while inserting the record in JDO

StackOverflow https://stackoverflow.com/questions/18058921

  •  23-06-2022
  •  | 
  •  

Question

Enity primary key is an auto_incrimented ID in JDO

@Persistent(primaryKey = "true", valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Column(name = "ID")
    private Long id;

When I am inserting any record, it's primary key ID is being set implicitly as auto_incremented.

I have a requirement in which I want set this ID (PK) using setter(setId()) explicitly while inserting the record.

Can we do this?

Était-ce utile?

La solution

No. As comments say, you either use IDENTITY strategy (so its set by the datastore), or you set it yourself. You can't have both

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top