[jboss-user] [JBoss and NetBeans] - Netbeans 6, Java Persistence API, Web Service using Annotati
jsolderitsch
do-not-reply at jboss.com
Tue Nov 27 16:56:16 EST 2007
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.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4108244#4108244
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4108244
More information about the jboss-user
mailing list