0

We are using custom hibernate table generator for our primary key like below,

@Id
@GenericGenerator(
    name = "primary_id",
    strategy = "com.common.identity.IdGenerator"
)
@GeneratedValue(
    generator = "primary_id"
)
@Column(
    name = "pk_id"
)
protected Long pkId

Also we use liquibase for our database migration. Is there any way to integrate the above generator into liquibase insert changeset?

If not, is there anyway to call a java class to get a value for specific column in insert query.

<update tableName="primary_id">
        <column name="next_val" valueComputed="call java class to get value"/>
    </update>
  • Well, you could create a [custom change](https://stackoverflow.com/questions/11987460/java-code-changeset-in-liquibase) for this particular migration. What is the use case, though? Can't you just pre-generate a pool of ids to be used in the migration? Why do the ids have to come from the generator, rather than being simply 'invented' and hardcoded? – crizzis Nov 02 '20 at 22:06
  • @crizzis i can't hardcode since it will conflict with the sequence value while we insert data from the application UI. – Ramachandran Murugaian Nov 02 '20 at 22:34
  • Is there really no reserved id pool you could use (did you start the sequence from 1)? As an alternative, you could hardcode the ids and only use the custom change to fast-forward the sequence, if that's possible with your custom implementation. In any case, I can't really see another option than using a custom change in one way or another – crizzis Nov 02 '20 at 22:43

0 Answers0