tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Davidson" <>
Subject RE: injection bug
Date Tue, 02 Feb 2010 17:57:18 GMT
Hi Jason.

No, you can have private in "A", and then a var of the same name (any
scope) in a child of "A".  However, for Design, NOT a good idea, as one
frequently finds either one's own foot (and/or leg) removed by an
explosively discharging projectile (and often same to one or more
colleagues) by this pattern.  But it is perfectly legal.  For design and
code stability, I would second your suggestion of a protected var.  

But it looks like what Christian is trying to accomplish here is an
injected value that was not (or can not be) annotated for whatever
reason in the parent class.  So I suspect he may have found, well not
sure if its an actual bug, more like a missing feature that ought to be
there?  Unless an annotation is getting deleted/dropped when the
hierarchy is getting walked, in which case, that IS a bug.


-----Original Message-----
From: Jason Russo [] 
Sent: Tuesday, February 02, 2010 8:46 AM
Subject: Re: injection bug

Pardon me for chiming in, but I would think that java rules ought to
prohibit you from declaring variable em in class B, since it is declared
private in class A.  Shouldn't you declare em as protected in class A

Jason Russo

Application Developer

Genscape- See the Energy

445 E. Market St, Suite 200

Louisville, KY 40202

Tel: 502-583-2091

On Mon, 2010-02-01 at 17:23 -0500, Christian Bourque wrote:

> Hi,
> I have a weird problem with injection and I would like to confirm
> whether or not it is a bug:
> public abstract class A
> {
>   private EntityManager em;
>   public EntityManager getEntityManager() { return em; }
>   public void setEntityManager(EntityManager em) { this.em = em; }
> }
> @Stateless
> public class B extends A implements IB
> {
>   @PersistenceContext
>   private EntityManager em;
>   @PostConstruct
>   public void init()
>   {
>     System.out.println("*** Entity Manager: " + em);
>     setEntityManager(em);
>   }
> }
> In B the injected entity manager is always null! And If I simply
> change the variable name to say "em2" then it works!
> Tested on OpenEJB 3.1.2...
> Thanks
> Christian

View raw message