Home

Add a comment

 

Re: JSR-299 & @Produces

Hi Ant,
Very interesting thought about @Produces. But I think I have to clarify some points you mentioned.

1) @Produces is a simple way to implement the Factory Method pattern. The examples in the specs are not very useful to understand that meaning of @Produces and don't show a good use case for @Produces.

2) The example of Section 1.3.3 is a workaround:
@Produces @PersistenceContext(unitName="UserData") @Users
EntityManager userDatabaseEntityManager;
And then here, the code which uses that entity manager:
@Inject @Users EntityManager userDatabaseEntityManager;
Because the Java EE resources like EntityManager are NOT CDI beans it's not possible to inject things like the EntityManger in a CDI bean. The first snippet is in a EJB where one have access to the EntityManager via @PersistenceContext and the second part is a CDI bean which uses the produced EntityManager.
I think this way will be obsolet with Java EE 7 when the JSF, CDI, EJB stuff is aligned.

Kind Regards, Simon

Re: JSR-299 & @Produces


Title
Body
HTML : b, strong, i, em, blockquote, br, p, pre, a href="", ul, ol, li, sub, sup
Name
E-mail address
Website
Remember me Yes  No 

E-mail addresses are not publicly displayed, so please only leave your e-mail address if you would like to be notified when new comments are added to this blog entry (you can opt-out later).