4 Replies Latest reply on Nov 30, 2007 2:22 PM by jsolderitsch

    Netbeans 6, Java Persistence API, Web Service using Annotati

    jsolderitsch

      I have a web service that depends on a MySQL DB. I am using the Java Persistence API for DB access and Web Services (JAX-WS) defined via annotations.

      Using Netbeans 6 (RC2) and the bundled glassfish app server, things are working. I needed to write virtually no configuration files (.xml) - the ones I needed were generated.

      I want to deploy to JBoss -- probably 4.2.2.

      Netbeans integration with JBoss seems to be at the J2EE 1.4 level. I want to use J2EE 5 techniques if possible and so it seems I need to manually deploy my war file to JBoss.

      My problem relates to what needs to be in the files:

      jboss-web.xml
      web.xml
      persistence.xml
      mysql-ds.xml

      in order that the persistence declarations and usages work.

      I have tried all sorts of things, picking hints off of the web, but I can't get the application to run.

      Can anyone relate experiences when porting from glassfish to jboss?

      A sample datasource file for MySQL that is suitable for use in a JBoss environment?

      Why the code:

      @WebService()
      @PersistenceContext(name = "persistence/LogicalName", unitName = "MissionStatusProjectPU2")
      public class MissionStatusService {
      EntityManager em;

      public MissionStatusService() {

      try {
      Context ctx = (Context) new javax.naming.InitialContext().lookup("java:comp/env");
      em = (EntityManager) ctx.lookup("persistence/LogicalName");
      } catch (NamingException ex) {
      ex.printStackTrace();
      }
      }

      fails in JBoss at the Context ctx statement with the error trace:

      14:12:59,849 ERROR [STDERR] javax.naming.NameNotFoundException: persistence not bound
      14:12:59,850 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      14:12:59,850 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      14:12:59,850 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      14:12:59,850 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
      14:12:59,850 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
      14:12:59,850 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
      14:12:59,850 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
      14:12:59,850 ERROR [STDERR] at com.gestalt.afmstt.modernization.MissionStatusService.(MissionStatusService.java:32)
      1

      (Line 32 in MissionStatusService is the Context line above)

      My current web.xml looks like:

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

      <servlet-name>MissionStatusServiceService</servlet-name>
      <servlet-class>com.gestalt.afmstt.modernization.MissionStatusService</servlet-class>
      <load-on-startup>1</load-on-startup>

      <servlet-mapping>
      <servlet-name>MissionStatusServiceService</servlet-name>

      <url-pattern>/MissionStatusServiceService</url-pattern>
      </servlet-mapping>
      <resource-ref>
      DB Connection
      <res-ref-name>jdbc/mysql_remote</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      <session-config>
      <session-timeout>
      30
      </session-timeout>
      </session-config>
      <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      </web-app>

      My jboss-web.xml looks like:

      <jboss-web>
      <resource-ref>
      <res-ref-name>jdbc/mysql_remote</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <jndi-name>java:mysql_remote</jndi-name>
      </resource-ref>
      </jboss-web>

      My persistence.xml looks like:

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
      <persistence-unit name="MissionStatusProjectPU2" transaction-type="JTA">
      <jta-data-source>mysql_remote</jta-data-source>

      </persistence-unit>


      and my mysql-ds.xml looks like:

      <?xml version="1.0" encoding="UTF-8"?>

      <!-- $Id: mysql-ds.xml 63175 2007-05-21 16:26:06Z rrajesh $ -->
      <!-- Datasource config for MySQL using 3.0.9 available from:
      http://www.mysql.com/downloads/api-jdbc-stable.html
      -->


      <local-tx-datasource>
      <jndi-name>mysql_remote</jndi-name>
      <connection-url>jdbc:mysql://10.5.100.39:3306/data_services</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>xxxx</user-name>
      yyyyt
      <!-- The minimum connections in a pool/sub-pool. Pools are lazily constructed on first use -->
      <min-pool-size>5</min-pool-size>

      <!-- The maximum connections in a pool/sub-pool -->
      <max-pool-size>20</max-pool-size>

      <!-- The time before an unused connection is destroyed -->
      <idle-timeout-minutes>5</idle-timeout-minutes>

      <exception-sorter-class-name>com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter</exception-sorter-class-name>
      <valid-connection-checker-class-name>com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker</valid-connection-checker-class-name>
      <!-- should only be used on drivers after 3.22.1 with "ping" support
      <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
      -->
      <!-- sql to call when connection is created
      <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->
      <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
      <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->

      <type-mapping>mySQL</type-mapping>

      </local-tx-datasource>


      Would appreciate any ideas, examples.

        • 1. Re: Netbeans 6, Java Persistence API, Web Service using Anno
          phejl

          Did the deployment proceed correctly? Any messages in the log?

          • 2. Re: Netbeans 6, Java Persistence API, Web Service using Anno
            jsolderitsch

             

            "phejl" wrote:
            Did the deployment proceed correctly? Any messages in the log?


            As far as I can tell looking at the run.sh console messages, the deployment succeeds.

            I see my data source created.

            But the application itself fails when I send a SOAP request to the web service.

            • 3. Re: Netbeans 6, Java Persistence API, Web Service using Anno
              phejl

              I some did more investigation with jboss 4.2.2 and jboss 5 beta2, here is what I observed (don't take it as an unchangeable fact).
              With jboss 4 it seems to me that PersistentContext in servlet or webservice is ignored completely (jboss 4 is not ee 5 certified - provides ejb3 and ee5 web apps, however not sure if wired properly).
              When using jboss 5 server noticed the annotation however wasn't able to load the proper context (maybe really problem with wiring jpa and web, since it is still beta).

              Maybe somebody from jboss could tell you more...
              P.

              • 4. Re: Netbeans 6, Java Persistence API, Web Service using Anno
                jsolderitsch

                 

                "phejl" wrote:
                I some did more investigation with jboss 4.2.2 and jboss 5 beta2, here is what I observed (don't take it as an unchangeable fact).
                With jboss 4 it seems to me that PersistentContext in servlet or webservice is ignored completely (jboss 4 is not ee 5 certified - provides ejb3 and ee5 web apps, however not sure if wired properly).
                When using jboss 5 server noticed the annotation however wasn't able to load the proper context (maybe really problem with wiring jpa and web, since it is still beta).

                Maybe somebody from jboss could tell you more...
                P.


                Thanks for doing some checking.

                I have been trying some of the Seam 2.0.0 demos (deploying to my 4.2.2 JBoss) and tutorials and ran seam-gen using my database.

                I got this to work. And in the set of generated files I see a persistence.xml and a components.xml.

                I think I see some interesting bits:

                In the generated persistence.xml I see:

                <persistence-unit name="AfmsttModernizationSeam">
                 <provider>org.hibernate.ejb.HibernatePersistence</provider>
                 <jta-data-source>java:/AfmsttModernizationSeamDatasource</jta-data-source>
                 <properties>
                 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                 <property name="hibernate.hbm2ddl.auto" value="validate"/>
                 <property name="hibernate.show_sql" value="true"/>
                 <property name="hibernate.format_sql" value="true"/>
                 <property name="jboss.entity.manager.factory.jndi.name" value="java:/AfmsttModernizationSeamEntityManagerFactory"/>
                 </properties>
                 </persistence-unit>


                and in components.xml I see:

                <persistence:managed-persistence-context name="entityManager"
                 auto-create="true"
                 persistence-unit-jndi-name="java:/AfmsttModernizationSeamEntityManagerFactory"/>
                


                These seem like config options that may help the wiring to complete the circuit if I add them in the right place in my war file.