I have this hibernation class with annotations:
@Entity public class SimponsFamily{ @Id @TableGenerator(name = ENTITY_ID_GENERATOR, table = ENTITY_ID_GENERATOR_TABLE, pkColumnName = ENTITY_ID_GENERATOR_TABLE_PK_COLUMN_NAME, valueColumnName = ENTITY_ID_GENERATOR_TABLE_VALUE_COLUMN_NAME) @GeneratedValue(strategy = GenerationType.TABLE, generator = ENTITY_ID_GENERATOR) private long id; ... }
Since I donβt want to comment out all the id fields of my classes this way, I tried to create a normal annotation:
@TableGenerator(name = ENTITY_ID_GENERATOR, table = ENTITY_ID_GENERATOR_TABLE, pkColumnName = ENTITY_ID_GENERATOR_TABLE_PK_COLUMN_NAME, valueColumnName = ENTITY_ID_GENERATOR_TABLE_VALUE_COLUMN_NAME) @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface EntityId { @GeneratedValue(strategy = GenerationType.TABLE, generator = ENTITY_ID_GENERATOR) public int generator() default 0; @Id public long id() default 0; }
so that I can use this annotation in my class:
@Entity public class SimponsFamily{ @EntityId private long id; ... }
I need to write @Id and @GeneratedValue at the field level, as they do not support TYPE RetentionPolicy. These solutions seem to work.
My questions:
How do field level annotations in my user annotations (and values) get transferred to my use of EntityId annotations?
What about the default values ββthat I set in my user annotation, are they used since I don't specify attributes when used?
Is this the preferred way to use field level annotations in annotations?
source share