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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:43:31+00:00 2026-05-26T02:43:31+00:00

I have some code along the lines of this: @EJB protected SomeService service; //

  • 0

I have some code along the lines of this:

@EJB
protected SomeService service;

// Somewhere in a method
service.getClass().getSimpleName();

What I was looking for was the name of the EJB class, which in this case should have been something along the lines of SomeServiceBean. What I get instead, however, is for example $Proxy2128.

Is there a way I can get the name of the actual EJB class that I implemented, instead of the proxy class?

Think we’re using ejb 3.0 with geronimo or something like that.

  • 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-26T02:43:32+00:00Added an answer on May 26, 2026 at 2:43 am

    It’s probably not a good idea to do this. I suspect you are better off doing something like adding a method to the bean which returns a type string that is under your control. The simplest such implementation

    public String getSimpleClassName() {
        return getClass().getSimpleName();
    }
    

    That is safe in the face proxying. It is not safe in the face of dynamic subclassing, but i don’t know of any EJB implementations that do that (although there are certainly JPA implementations which do that).

    A slightly more complicated, but fundamentally more straightforward, implementation would be to define:

    public abstract String getSimpleClassName();
    

    in a base class (or interface), and then writing:

    public String getSimpleClassName() {
        return SomeService.class.getSimpleName();
    }
    

    In SomeService. That is cast-iron guaranteed to work.

    Alternatively, if you are working with no-interface views, and don’t mind reflection, and the risk of your system bursting into flames at any moment, then in the calling code, you can do:

    private String findBeanClassName(Object beanRef) {
        return findBeanClass(beanRef).getSimpleName();
    }
    
    private Class<?> findBeanClass(Object beanRef) {
        return findAncestorWithAnnotation(beanRef.getClass(), Stateless.class);
    }
    
    private Class<?> findAncestorWithAnnotation(Class<?> cl, Class<? extends Annotation> annotation) {
        while ((cl != null) && !cl.isAnnotationPresent(annotation)) {
            cl = cl.getSuperclass();
        }
        return cl;
    }
    

    That ought to work. Obviously, you’d need to use a different annotation class if you are using a stateful bean.

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

Sidebar

Related Questions

I have some code in app along the lines of DateTime activityDate = DateTime.Parse(tempDate
I'm currently writing some code where I have something along the lines of: double
I have some code like this in a winforms app I was writing to
I have some code like this: If key.Equals(search, StringComparison.OrdinalIgnoreCase) Then DoSomething() End If I
I have some VERY inefficient code in which many lines appear 4 times as
I have some code which draws a line along the x, y and z
I have some code shared among multiple projects in a static library. Even with
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
I have some code which collects points (consed integers) from a loop which looks
I have some code in a javascript file that needs to send queries back

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.