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 7159091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:10:22+00:00 2026-05-28T13:10:22+00:00

I’m trying to send events and do this generically. I mean – create one

  • 0

I’m trying to send events and do this generically. I mean – create one abstract base DAO class with generic type and fire the event from its method. This should work for all descendants. This works if I define the exact type, but doesn’t – if I use generics. What I mean:

AbstractDAO (with generics – doesn’t fire the event):

public abstract class AbstractDAO<T extends Persistable> implements Serializable {
   @Inject @PostSaveEvent Event<T> postSaveEvent;

   public T saveOrUpdate(T object) throws DatabaseException {
      T obj = em.merge(object);

      postSaveEvent.fire(obj);
   }
}

AbstractDAO (no generics, just simple class cast – fires the event):

public abstract class AbstractDAO<T extends Persistable> implements Serializable {
   @Inject @PostSaveEvent Event<Polis> postSaveEvent;

   public T saveOrUpdate(T object) throws DatabaseException {
      T obj = em.merge(object);

      postSaveEvent.fire((Polis)obj);
   }
}

PolisDAO class, which extends AbstractDAO and defines the generic type:

@Stateless
@Named
@PolisType
public class PolisDAO extends AbstractDAO<Polis> {
   // some methods (saveOrUpdate is not overriden!)
}

My observer class:

@Stateless
@Named
public class ProlongationService {

    public void attachProlongationToPolisOnSave(@Observes @PostSaveEvent Polis polis) throws DatabaseException {
        // ... DO smth with polis object. This is NOT called in the first case and  called in the second
    }

THis is very strange for me, as “fire()” method for CDI event should define the event type on runtime, not during compilation or deployment… When I debug, I see, that

postSaveEvent.fire(obj);

from the first sample operates exactly with Polis entity. But no event is fired nevertheless…

Upd. I tried the base generic class, but no luck:

@Inject @PostSaveEvent Event<Persistable> postSaveEvent;

Thanks.

  • 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-28T13:10:23+00:00Added an answer on May 28, 2026 at 1:10 pm

    This should, in theory, work, however in practice inspecting the type of generic objects at runtime with Java Reflection is, at times, impossible. This is due to type erasure. IIRC the type of the concrete sub class isn’t erased, so it should be possible to reconnect this, but I guess the implementation isn’t doing this right now.

    File this as a bug in the http://issues.jboss.org/browse/WELD issue tracker (if you are using Weld), with the classes you provide as an example and we can try to fix it.

    To work around, try injecting the event into the concrete subclass, and passing it as an argument, or using an accessor method, to get it into the abstract super class.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.