This was a deliberate decision. I understand that testing might get more complicated, but you really shouldn’t rely on fixed id values if you have a generator. This can lead to lot’s of other problems.
I think if you’re using Quarkus, Spring or other containers, you should be able to create a class like this and mark it as a bean to make this work:
public class SequenceOrAssignedGenerator extends SequenceStyleGenerator {
@Override
public Object generate(SharedSessionContractImplementor session, Object owner) throws HibernateException {
final Long id;
if ( owner instanceof MyEntity ) {
id = ( (MyEntity) owner ).getId();
}
else {
id = null;
}
return id != null ? id : super.generate( session, owner );
}
@Override
public boolean allowAssignedIdentifiers() {
return true;
}
}
Please let us know if it does. Maybe you can even contribute a section in the migration guide for ORM 6.6 that explains this “workaround”?
Sure. We understand this. But we have some legacy code in the older version of our application and we don’t want to invest so much in that direction.
Please let us know if it does
Thanks! This magic property works for us.
We already had a custom IdGenerator with the logic that you have shared in the overridden generate method but without allowAssignedIdentifiers property it did not work.
Maybe you can even contribute a section in the migration guide for ORM 6.6 that explains this “workaround”?