Pierre Guillemot [https://community.jboss.org/people/hnb] created the discussion
"ClassCastException" To view the discussion, visit: https://community.jboss.org/message/715961#715961 -------------------------------------------------------------- Hello there, i am new to JBoss AS, i am currently using JBoss AS6.0 final, MySQL and Netbeans 7.1. I finally managed to configure the MySqlDS.xml and persistence.xml, i can see in the logs that the PU is read and all, the database is accessed, everything is working. In order to try my datasource access in created a simple servlet : @WebServlet(name = "Test", urlPatterns = {"/Test"}) public class Test extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { /* * TODO output your page here. You may use following sample code. */ out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Test</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet Test at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); Context context; try { context = new InitialContext(); DataSource data = (DataSource)context.lookup("java:/MySqlDs"); } catch (NamingException ex) { Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex); } } finally { out.close(); } } Except that in have this error : 23:01:32,412 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/YouFoodInc].[Test]] "Servlet.service()" pour la servlet Test a généré une exception: java.lang.ClassCastException: org.jboss.jpa.injection.InjectedEntityManagerFactory cannot be cast to javax.sql.DataSource at Test.processRequest(Test.java:57) at Test.doGet(Test.java:80) at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [:1.0.0.Final] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [:1.0.0.Final] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.Final] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final] at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) [:6.0.0.Final] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.Final] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.Final] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.Final] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.Final] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final] at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final] at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final] at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.Final] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.0.0.Final] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final] at java.lang.Thread.run(Unknown Source) [:1.6.0_27] I added the mysql-connector-java-5.1.13-bin.jar inside the serverd/default/lib. And I have not added anything else inside the lib folder. I already did this kind of thing using GlassFish 3.0, and i never had any issues. If you need any other informations, please tell me. Thank you for your attention, Regards, Pierre. -------------------------------------------------------------- Reply to this message by going to Community [https://community.jboss.org/message/715961#715961] Start a new discussion in Datasource Configuration at Community [https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077]
_______________________________________________ jboss-user mailing list [email protected] https://lists.jboss.org/mailman/listinfo/jboss-user
