Mantis - Resin
Viewing Issue Advanced Details
4488 minor always 04-07-11 20:27 08-01-11 18:48
reza  
ferg  
normal  
closed 4.0.17  
fixed  
none    
none 4.0.21  
0004488: @DataSourceDefinition does not work with JPA (timing issue)
The @DataSourceDefinition annotation does not work with JPA due to timing issues. It looks like JPA is getting bootstrapped before the data source is being bound to JNDI. It does not matter if the data source is defined on Servlet, EJB or CDI. Injecting the bound data source does work since there are no timing issues in that case. Here is an example data source definition:

@DataSourceDefinition(
    name = "java:app/jdbc/AcmeBankDB3",
    className = "com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource",
    url = "jdbc:mysql://localhost:3306/acmebank", [^]
    serverName = "localhost",
    portNumber = 3306,
    databaseName = "acmebank",
    user = "root",
    password = "gemini6")
@WebServlet(name = "DataPopulatorServlet", urlPatterns = { "/populate" })
public class DataPopulatorServlet extends HttpServlet {
  ...
}

The following persistence.xml will cause the application deployment to fail (JPA will not find the data source):

<persistence>
  <persistence-unit name="acme-bank-db" transaction-type="JTA">
    <jta-data-source>java:app/jdbc/AcmeBankDB3</jta-data-source>
    <validation-mode>AUTO</validation-mode>
    <properties>
      <property name="eclipselink.ddl-generation" value="create-tables" />
      <property name="eclipselink.logging.level" value="INFO" />
    </properties>
  </persistence-unit>
</persistence>

Injecting the plain data source will work:

public class DefaultUserDao implements UserDao {
  @Resource(lookup = "java:app/jdbc/AcmeBankDB3")
  private DataSource dataSource;
  ...
}

Notes
(0005414)
ferg   
08-01-11 18:48   
env/0ea0