You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Shing Hing Man (JIRA)" <ji...@apache.org> on 2013/01/27 18:15:14 UTC

[jira] [Issue Comment Deleted] (TAP5-1910) JPA and JBoss 7 datasources

     [ https://issues.apache.org/jira/browse/TAP5-1910?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Shing Hing Man updated TAP5-1910:
---------------------------------

    Comment: was deleted

(was: I have run into the same problem as Miguel.

I solved it by creating JpaSymbols.INITIAL_CONTEXT with default value "java:comp/env" in JpaModule.
But not sure if it is the best approach.

The initialContext is injected into the constructor of EntityManagerSourceImpl :

public EntityManagerSourceImpl(Logger logger, @Symbol(JpaSymbols.PERSISTENCE_DESCRIPTOR)
    final Resource persistenceDescriptor,
    @Symbol(JpaSymbols.INITIAL_CONTEXT) String initialContext,
    @Local PersistenceUnitConfigurer packageNamePersistenceUnitConfigurer,
                                   Map<String, PersistenceUnitConfigurer> configuration)

In the constructor of EntityManagerSourceImpl, the intialContext is passed to PersistenceUnitInfo via PersistenceParser and
PersistenceContentHandler.

Then in method PersistenceUnitInto.lookupDataSource :
    
    // initialContext is passed down from EntityManagerSourceImpl
    final Context envContext = (Context) initContext.lookup(initialContext);


To set my own initialContext, I just add the following in my AppModule :


 public static void contributeApplicationDefaults(
            MappedConfiguration<String, String> configuration)
    {
  
        configuration.add(JpaSymbols.INITIAL_CONTEXT,"java:");
    }
    

)
    
> JPA and JBoss 7 datasources
> ---------------------------
>
>                 Key: TAP5-1910
>                 URL: https://issues.apache.org/jira/browse/TAP5-1910
>             Project: Tapestry 5
>          Issue Type: Bug
>          Components: tapestry-jpa
>    Affects Versions: 5.3.2
>            Reporter: Miguel Figueiredo
>
> Hello,
> I am using tapestry 5.3.2 with JBoss 7, and I'm having some problems
> when using a JBoss datasource with JPA.
> My datasource configuration:
>                <datasource jta="false"
> jndi-name="java:jboss/myDatasource" pool-name="mysqlDS" enabled="true"
> use-java-context="true" use-ccm="true">
>                    (...)
>                </datasource>
> My persistence.xml configuration:
>    <persistence-unit name="my-pu"
>        transaction-type="RESOURCE_LOCAL">
>        <provider>org.hibernate.ejb.HibernatePersistence</provider>
>        <non-jta-data-source>java:jboss/myDatasource</non-jta-data-source>
>        (...)
>    </persistence-unit>
> Looking at the code in the PersistenceUnitInfoImpl of tapestry-jpa
> 5.3.2 I found the following:
>    private DataSource lookupDataSource(final String name)
>    {
>        try
>        {
>            // TODO: Create InitialContext with environment properties?
>            final Context initContext = new InitialContext();
>            final Context envContext = (Context) initContext.lookup("java:comp/env");
>            return (DataSource) envContext.lookup(name);
>        } catch (final NamingException e)
>        {
>            throw new RuntimeException(e);
>        }
>    }
> In JBoss 7 the env context should be retrieved from java:jboss, e.g.:
>            final Context initContext = new InitialContext();
>            final Context envContext = (Context)initContext.lookup("java:jboss");
>            return (DataSource) envContext.lookup("myDatasource");
> Maybe a datasource lookup class could be configured here.
> Best regards,
> Miguel

--
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