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

  • SEARCH
  • Home
  • 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 5969377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:13:19+00:00 2026-05-22T20:13:19+00:00

This question regards how one can effectively create and persist event domain objects on

  • 0

This question regards how one can effectively create and persist event domain objects on certain system or user triggered events which themselves may or may not persist changes to the database.

Im creating a system where a user can tag some object, and when tagging occurs i should create a UserTagEvent which holds the object that was tagged, the tag that was applied or removed, and the user that tagged the object. (EDIT: This is not the actual TAG object, just a log of a tagging event)

The relationship of such a taggable object is one-to-many (a taggable object has many tags)

As far as i can see i have three alternatives.

  1. Inline code in the controller/service which does the tagging (don’t wanna do this as it mixes two different business processes.)
  2. Use hibernate listeners pre-collection-update and post-collection-update to fetch the necessary information and create and persist a new UserTagEvent
  3. Use AOP.

Do i have any other alternatives? Has anyone done something similar to this? What do you guys think i should do? Any help is appreciated.

  • 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-22T20:13:20+00:00Added an answer on May 22, 2026 at 8:13 pm

    The following is what i learned when exploring my options:

    1) Inline code in the controller/service which does the
    tagging (don’t wanna do this as it
    mixes two different business
    processes.)

    Didnt give this alternative a try

    2) Use hibernate listeners pre-collection-update and
    post-collection-update to fetch the
    necessary information and create and
    persist a new UserTagEvent

    This turned out to be very difficult, inefficient, and problematic for several reasons.

    For example, you are working with a collection of items which may or may not be lazy initialized. In order to detect changes in the collection i had to listen for collection initialization event, get a cloned collection, store it to a field variable, then listen for a update collection event, get a cloned collection and compare with the collection previously stored.

    In addition these events got fired for ALL hibernate events, not just for the domain objects i was interested in. So this was a “no go”…

    3) Use AOP.

    I was originally very optimistic about this solution, and after a few tries i soon came to realize that this wasn’t as simple as i first thought. There were very few guides on the web describing Grails AND AOP, and those existed were rather old.

    There was a lot more work involved than i originally thought. My overall impression is that grails seems to have a lot of bugs assosciated with AOP integration, and i also didn’t like the fact that i had to add bean definitions to resources.groovy for each aspect that i created. I tried to make aspects be autoloaded through annotations (auto-proxy), but with no luck.

    In addition i never got the pointcut to work outside the main project. As my tagging solution is defined as a grails plugin it seems that AOP can’t be applied on classes of the plugin (even if it is a inplace plugin).

    So this turned out to be a “no go” aswell

    So drum roll please.

    What i ended up with was using the observer pattern to fire off an event whenever a new tag was added or removed. This involved making changes to my tagger plugin where i could specify listeners through spring beans (whicn implemented a TagEventListener interface) and have the tagger plugin fire off events on the spring beans upon the addTag and removeTag method calls.

    Overall im pretty happy with this solution, it involves one or two more method calls then what would be necessary if i had just inlined as described in option 1. But this way I have cleaner code, and i don’t mix business processes. So i think the extra 1ns overhead is worth it.

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

Sidebar

Related Questions

I'm pretty sure this is a simple question in regards to formatting but here's
First of all, this question is in regards to PHP and MySQL I have
This may be a simple question or a pretty complex one, ill let you
I have one more question related to this thread. How to decode some number
This question regards my personal photography website. I use the following javascript to generate
I suppose this question could just as easily be applied to PHP with regard
This question is kind of an add-on to this question In C#, a switch
This question and answer shows how to send a file as a byte array
This question comes on the heels of the question asked here . The email
This question would probably apply equally as well to other languages with C-like multi-line

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.