You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltaspike.apache.org by "Arne Limburg (JIRA)" <ji...@apache.org> on 2013/02/18 23:55:12 UTC

[jira] [Commented] (DELTASPIKE-315) Provide a producer for EntityManagerFactories

    [ https://issues.apache.org/jira/browse/DELTASPIKE-315?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13580873#comment-13580873 ] 

Arne Limburg commented on DELTASPIKE-315:
-----------------------------------------

Imho we should work on a more general and configurable solution.
My proposial would look like this:

@Inject @MyCustomQualifier
private EntityManager em;

@Qualifier
@DeltaspikeManaged(@PersistenceContext(...))
public @interface MyCustomQualfier {
}

where @PersistenceContext is the javax.persistence.PersistenceContext

And along with this we should support
@Produces
@MyCustomQualifier
@Named("javax.persistence.jtaDataSource")
public String myDataSourceJndiName = "jndi:...";

and all other persistence properties and a producer for the scope of the EntityManager:
@Produces
@MyCustomQualifier
private Class<? extends Annotation> entityManagerScope = RequestScoped.class

Wdyt?
                
> Provide a producer for EntityManagerFactories
> ---------------------------------------------
>
>                 Key: DELTASPIKE-315
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-315
>             Project: DeltaSpike
>          Issue Type: Bug
>          Components: JPA-Module
>    Affects Versions: 0.3-incubating
>            Reporter: Mark Struberg
>            Assignee: Mark Struberg
>             Fix For: 0.4-incubating
>
>
> I found myself using the following pattern quite often in projects in the last time. I have a @Qualifier UnitName(value) and a producer for a @Dependent EntityManagerFactory for it. The configuration is mostly provided via the persistenceProperties Map in EntityManagerFactory#createEntityManagerFactory(unitname, persistenceProperties);
> We can further tweak the config lookup path and define a route which makes the most sense.
> This can be used to create the EntityManager producer very easily.
> @ApplicationScoped
> public class MyEntityManagerProducer {
>   private @Inject @UnitName("orderUnit") EntityManagerFactory emf;
>   
>   @Produces @RequestScoped
>   public EntityManager createEm() {
>     return emf.createEntityManager();
>   }
>   .. + disposer 
> }
> Please note that the EMF producer doens't clash with anything else as it only produces EMFs with the Qualifier @UnitName!

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira