All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hyperfoil.tools.horreum.entity.CustomSequenceGenerator Maven / Gradle / Ivy

package io.hyperfoil.tools.horreum.entity;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.hibernate.annotations.IdGeneratorType;

/**
 * CustomSequenceGenerator is an annotation used to specify a custom
 * sequence-based primary key generator for entity fields or methods.
 * It utilizes the {@link SeqIdGenerator} class to generate the IDs,
 * which is a custom generator that does not generate the ID when
 * it is already provided and greater than 0.
 *
 * 

* This annotation should be applied at the field or method level. *

* *

* Example usage: *

* *
 * {@code
 *
 *     @Entity
 *     public class YourEntity {
 *
 *         @Id
 *         @GeneratedValue(generator = "schemaIdGenerator")
 *         @CustomSequenceGenerator(name = "schema_id_seq", initialValue = 1, allocationSize = 1)
 *         private Long id;
 *
 *         // other fields, getters, and setters
 *     }
 * }
 * 
* * @see SeqIdGenerator */ @IdGeneratorType(SeqIdGenerator.class) @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.FIELD }) public @interface CustomSequenceGenerator { /** * (Optional) The name of the database sequence object from * which to obtain primary key values. */ String name(); /** * (Optional) The value from which the sequence object * is to start generating. */ int initialValue() default 1; /** * (Optional) The amount to increment by when allocating * sequence numbers from the sequence. */ int allocationSize() default 50; }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy