1

I have defined an entity as so:

public class Chair {

    @GenericGenerator(name = "sequencePerEntityGenerator", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = {
            @Parameter(name = "prefer_sequence_per_entity", value = "true"),
            @Parameter(name = "sequence_per_entity_suffix", value = "_seq"),
            @Parameter(name = "initial_value", value = "5000000"),
            @Parameter(name = SequenceStyleGenerator.INCREMENT_PARAM, value = "1") })
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "sequencePerEntityGenerator")
    @Id
    int id;

But i would like to know what are the names of the sequences created (using Chair.class), and extract names/use dialect to create a nextval call of my own, and query a new ID without any .persist() call is made. Is this possible? If yes how so? If not how else?

My final aim is to query multiple IDs (upto millions) using a single SQL statement as provided in this stackoverflow question, in an existing application. (Other options for the same in MySQL, Postgres exist as separate answers to other questions)

PS: One may recommend using PooledOptimizer or HiLo Optimizer or any Client-ended optimizers already provided by hibernate to optimize ID generation, but given the heavy load my application has due to other processes, it is unable to allocate enough CPU time to sequence optimizers, and the synchronized generate methods of these optimizers blocks threads (asynchronous persistence). Incidentally, using optimizers slows down multi-threaded persist calls on the same Entity class, and is slower than NoopOptimizer (no optimizer).

0 Answers0