set auto_incremented primary key explicitly while inserting the record in JDO

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

  •  23-06-2022
  •  | 
  •  

سؤال

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?

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top