I found a pattern in my JPA mappings that I would like to codify. The following is a simple example:
@OneToMany(fetch=FetchType.EAGER) @Sort(type=SortType.NATURAL) private SortedSet<Item> items;
I would like to create a single SortedOneToMany annotation that I can apply to the set above:
public @interface SortedOneToMany { FetchType fetch() default EAGER; SortType sort() default NATURAL; Class comparator() default void.class; }
I wrote the following aspect to โattachโ JPA annotations whenever it sees my annotation:
public aspect SortedOneToManyAspect { declare @field: @SortedOneToMany * * : @OneToMany(fetch=FetchType.EAGER); declare @field: @SortedOneToMany * * : @Sort(type=SortType.NATURAL); }
But I do not know how I can access the values โโof the SortedOneToMany annotation parameters and use them when defining OneToMany and Sort annotations. There may be times when I want to change one of the default values:
@SortedOneToMany(sort=SortType.COMPARATOR,comparator=ItemComparator.class) private SortedSet<Item> items;
So, how can I pass annotation values โโfrom SortedOneToMany to Sort annotation?
Adam howard
source share