Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5947903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:01:52+00:00 2026-05-22T17:01:52+00:00

I have discovered a pattern in my JPA mappings that I would like to

  • 0

I have discovered a pattern in my JPA mappings that I would like to codify. A simple example follows:

@OneToMany(fetch=FetchType.EAGER)
@Sort(type=SortType.NATURAL)
private SortedSet<Item> items;

I would like to create a single annotation called SortedOneToMany that I can apply to the above set:

public @interface SortedOneToMany {
    FetchType fetch() default EAGER;
    SortType sort() default NATURAL;
    Class comparator() default void.class;
}

I have written the following aspect to “attach” the 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 don’t know how can I access the values of the SortedOneToMany annotation parameters and use them when defining the OneToMany and Sort annotations. There may be cases where I want to change one of the default values like so:

@SortedOneToMany(sort=SortType.COMPARATOR,comparator=ItemComparator.class)
private SortedSet<Item> items;

So how can I pass the annotation values from SortedOneToMany to the Sort annotation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:01:53+00:00Added an answer on May 22, 2026 at 5:01 pm

    I received this answer from Andy Clement on the aspectj-users mailing list:

    Hi,

    I’m afraid you can’t do that with AspectJ right now, you can’t pass a
    piece of the matched information to the new annotation. I can perhaps
    imagine some hypothetical syntax:

    declare @field:
    @SortedOneToMany(sort=SortType.COMPARATOR,comparator={1}) * * :
    @Sort(type=SortType.COMPARATOR,comparator={1});

    which would seem to achieve what you want.

    Maybe raise an enhancement request for it:
    https://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ

    sorry I don’t have better news.

    cheers
    Andy

    I created a ticket for the issue in case anyone wants to follow the progress: https://bugs.eclipse.org/bugs/show_bug.cgi?id=345515

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have discovered recently that's possible to call anoymous blocks from jdbc like this:
We have discovered that one of our auto generated assemblies is throwing a StackOverflowException
I have discovered that it is possible to populate resource strings with variable information
My testers have discovered that if you type free text into a file upload
I've been playing about with Runnable s and have discovered that if you postDelayed
While debugging an issue with our system, I have discovered a thread contention that
As well as my question Removing MKMapView Annotations causes leaks. I have discovered that
I have just discovered a variable name that is misspelled. If it were hidden
I have recently discovered that I am affected by this bug http://www.mail-archive.com/mono-bugs@lists.ximian.com/msg71515.html Well, at
I've recently discovered that MVC is supposed to have two different flavors, model one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.