0 Replies Latest reply on Jul 27, 2002 10:20 AM by niksa_os

    JNDI, JBoss3 and MySQL

    niksa_os Newbie

      I need to deploy my .ear on JBoss 3 and MySQL. And I don't know anything about JBoss. So, I need some help.

      I ask admin about JNDI names and agreement was:

      All jndi names and Database config must be in jar, war or ear. He can't change any xml files on JBoss server.
      Whether it can be done that way?

      When I call Entity from Session EJB, local call, it must look like this:
      InitialContext init = new InitialContext();
      UserHome userHome = (UserHome)init.lookup("java:orderentry/User"); or
      UserHome userHome = (UserHome)init.lookup("java:comp/env/ejb/orderentry/User");

      And in Session I have direct call, local call, to DB:
      InitialContext init = new InitialContext();
      DataSource source = (DataSource)init.lookup("java:orderentry/OrderEntryDS"); or
      DataSource source = (DataSource)init.lookup("java:comp/env/ejb/orderentry/OrderEntryDS");
      con = source.getConnection();

      URL: jdbc:mysql://localhost/ORDER_ENTRY
      Driver: org.gjt.mm.mysql.Driver

      In servlets I have local call to SessionEJB too:
      InitialContext init = new InitialContext();
      viewAllLocalHome = (ViewAllLocalHome)init.lookup("java:orderentry/ViewAll"); or
      viewAllLocalHome = (ViewAllLocalHome)init.lookup("java:comp/env/ejb/orderentry/ViewAll");

      Currently my ejb-jar.xml is:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      <enterprise-beans>

      <display-name>ViewAll</display-name>
      <ejb-name>ViewAll</ejb-name>
      <local-home>orderentry.ViewAllLocalHome</local-home>
      orderentry.ViewAllLocal
      <ejb-class>orderentry.ViewAllBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
      <ejb-local-ref>

      <ejb-ref-name>ejb/User</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <local-home>orderentry.UserHome</local-home>
      orderentry.User
      <ejb-link>User</ejb-link>
      </ejb-local-ref>


      <display-name>Orders</display-name>
      <ejb-name>Orders</ejb-name>
      <local-home>orderentry.OrdersHome</local-home>
      orderentry.Orders
      <ejb-class>orderentry.OrdersBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Orders</abstract-schema-name>
      <cmp-field>
      <field-name>id</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>userId</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>orderName</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>productName</field-name>
      </cmp-field>
      <primkey-field>id</primkey-field>


      <display-name>User</display-name>
      <ejb-name>User</ejb-name>
      <local-home>orderentry.UserHome</local-home>
      orderentry.User
      <ejb-class>orderentry.UserBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>User</abstract-schema-name>
      <cmp-field>
      <field-name>id</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>address</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>city</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>country</field-name>
      </cmp-field>
      <primkey-field>id</primkey-field>

      <query-method>
      <method-name>findAll</method-name>
      <method-params />
      </query-method>
      <result-type-mapping>Local</result-type-mapping>
      <ejb-ql>SELECT OBJECT (myUser) FROM User myUser</ejb-ql>


      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>user-orders</ejb-relation-name>
      <ejb-relationship-role>
      user
      <ejb-relationship-role-name>UserRelationshipRole</ejb-relationship-role-name>
      One
      <relationship-role-source>
      user
      <ejb-name>User</ejb-name>
      </relationship-role-source>
      <cmr-field>
      orders
      <cmr-field-name>orders</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      orders
      <ejb-relationship-role-name>OrdersRelationshipRole</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      orders
      <ejb-name>Orders</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>

      <assembly-descriptor>
      <container-transaction>

      <ejb-name>Orders</ejb-name>
      <method-name>*</method-name>


      <ejb-name>User</ejb-name>
      <method-name>*</method-name>


      <ejb-name>ViewAll</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>


      And web.xml is:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
      <web-app>

      <servlet-name>servlet1</servlet-name>
      <servlet-class>orderentry.Servlet1</servlet-class>


      <servlet-name>servlet2</servlet-name>
      <servlet-class>orderentry.Servlet2</servlet-class>

      <servlet-mapping>
      <servlet-name>servlet1</servlet-name>
      <url-pattern>/servlet1</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
      <servlet-name>servlet2</servlet-name>
      <url-pattern>/servlet2</url-pattern>
      </servlet-mapping>
      <ejb-local-ref>
      <ejb-ref-name>ejb/ViewAll</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      <local-home>orderentry.ViewAllLocalHome</local-home>
      orderentry.ViewAllLocal
      <ejb-link>ViewAll</ejb-link>
      </ejb-local-ref>
      </web-app>


      When I try this at home in JBoss3 with init.lookup("java:comp/env/ejb/ViewAll"); everything goes OK. I can use Hypersonic too.
      How can I change JNDI name and how can I connect to MySQL?

      Thanks