Anonymous | Login | Signup for a new account | 12-17-2024 10:45 PST |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ View Advanced ] [ Issue History ] [ Print ] | ||||||||
ID | Category | Severity | Reproducibility | Date Submitted | Last Update | ||||
0004502 | [Resin] | minor | always | 04-13-11 13:07 | 04-26-11 16:54 | ||||
Reporter | reza | View Status | public | ||||||
Assigned To | ferg | ||||||||
Priority | normal | Resolution | fixed | ||||||
Status | closed | Product Version | 4.0.17 | ||||||
Summary | 0004502: Loading JPA fails in JUnit due to data source JNDI registry ordring issues | ||||||||
Description |
Loading JPA is failing in JUnit because the JPA bootstrap happens before the data source is registered in JNDI. For example, the following code will fail to deploy: ================================================================================ <beans> <database> <jndi-name>jdbc/test</jndi-name> <driver> <type>com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource</type> <url>jdbc:mysql://localhost:3306/test</url> [^] <user></user> <password></password> </driver> </database> </beans> ================================================================================ ================================================================================ <persistence> <persistence-unit name="test" transaction-type="JTA"> <jta-data-source>jdbc/test</jta-data-source> <properties> <property name="eclipselink.ddl-generation" value="create-tables" /> <property name="eclipselink.logging.level" value="FINEST" /> </properties> </persistence-unit> </persistence> ================================================================================ ================================================================================ package qa; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; public class TestBean { @PersistenceContext private EntityManager entityManager; public void hit() { System.out.println("hit(" + entityManager + ")"); } } ================================================================================ ================================================================================ package qa; import javax.inject.Inject; import org.junit.Test; import org.junit.runner.RunWith; import com.caucho.junit.ResinBeanContainerRunner; @RunWith(ResinBeanContainerRunner.class) public class JUnitTest { @Inject private TestBean bean; @Test public void test() { bean.hit(); } } ================================================================================ This is definitely a timing issue specific to JUnit/the bean container because the same code works fine in a web application, loaded via a Servlet: ================================================================================ package qa; import java.io.IOException; import javax.inject.Inject; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet(name = "TestServlet", urlPatterns = { "/test" }) public class TestServlet extends HttpServlet { private static final long serialVersionUID = 1L; @Inject private TestBean bean; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { bean.hit(); } } ================================================================================ This is pretty serious since loading JPA is critical to most Java EE integration testing. |
||||||||
Additional Information | |||||||||
Attached Files | |||||||||
|
Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
29 total queries executed. 26 unique queries executed. |