Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0004488 [Resin] minor always 04-07-11 20:27 08-01-11 18:48
Reporter reza View Status public  
Assigned To ferg
Priority normal Resolution fixed  
Status closed   Product Version 4.0.17
Summary 0004488: @DataSourceDefinition does not work with JPA (timing issue)
Description 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;
  ...
}
Additional Information
Attached Files

- Relationships

- Notes
(0005414)
ferg
08-01-11 18:48

env/0ea0
 

- Issue History
Date Modified Username Field Change
04-07-11 20:27 reza New Issue
08-01-11 18:48 ferg Note Added: 0005414
08-01-11 18:48 ferg Assigned To  => ferg
08-01-11 18:48 ferg Status new => closed
08-01-11 18:48 ferg Resolution open => fixed
08-01-11 18:48 ferg Fixed in Version  => 4.0.21


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
29 total queries executed.
26 unique queries executed.
Powered by Mantis Bugtracker