so I have custom IdGenerator like that:
@Service
public class IdGenerator extends SequenceStyleGenerator {
private final SequenceRepository sequenceRepository;
public IdGenerator(SequenceRepository sequenceRepository) {
this.sequenceRepository = sequenceRepository;
}
@Override
public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
BaseObject type = ((BaseObject) object);
return StringUtils.getNumberWithMaxRadix(sequenceRepository.getNext(type.sequenceName()));
}
}
And on Entity Id field Hibernate annotations:
@Id
@Column(name = "id", nullable = false, length = 18)
@SequenceGenerator(name = "location_road_seq", sequenceName = "location_road_seq", allocationSize = 10)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "location_road_seq")
@GenericGenerator(
name = "location_road_seq",
strategy = "com.wildtigerrr.bestgamebot.bin.service.base.IdGenerator",
parameters = {
@org.hibernate.annotations.Parameter(name = IdGenerator.VALUE_PREFIX_PARAMETER, value = "a0lr")
})
private String id;
When inserting objects from the code with Hibernate - works like a charm. But I need to insert initial data with Liquibase, and here I have issues inserting data from Liquibase changeset:
INSERT INTO location (id, system_name)
VALUES (nextval('location_seq'), 'TestLocation');
Returns simple values from sequence as Id.
Is there an option and how should I configure Liquibase to use my IdGenerator?
And if it's not possible, what's best practices/possible solutions for overcoming that issue? Any feedback would be appreciated!