DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    19

    Help! JBoss/EJB-CMP - database connection problem!

    CMP - failed to retrieve data from database - but NO exception..

    Hi, I've developed this simple CMP to retrieve user Group information from database. It failed to retrieve data from database but no exception is thrown (Yes, I stepped through the code, nothing happenned). And now I'm kind of stuck without any error message to start debuggin with. So, I'm just asking for general advice/direction...

    1. CLIENT side
    Here's the Strut's action class ** ie. the CLIENT ** (yes, that's where they retrieve local proxy to CMP directly, as opposed to doing it thru a session bean):

    Code:
    try {
    ...
    ...
    BasicConfigurator.configure();
    logger.debug("PrepareLoginAction invoked");
    		    
    context = new InitialContext();
    Object ref = context.lookup(groupJNDI);
    home = (GroupLocalHome)PortableRemoteObject.narrow(ref, GroupLocalHome.class);
    
    ******** THAT's MY CMP local proxy: GroupLocal, Nothing is retrieved here but NO EXCEPTION ********
    groups=home.findAllGroups(); 
    ...				
    return mapping.findForward("success");
    ...
    } catch(Exception e) {
      ***** NO EXCEPTION CAUGHT *****
    }
    2. The CMP GroupBean:
    Code:
    /**
     *  @author norman_lm_fung@hotmail.com
     *
     *  @ejb.bean	
     * 			name="GroupEJB"
     * 			local-jndi-name="ejb/UserGroup"
     * 			display-name="User Group EJB"
     * 			description="User Group EJB"
     * 			cmp-version="2.x"
     * 			type="CMP"
     * 			view-type="local"
     * 			schema="Group"
     * 			reentrant="false"
     * 			primkey-field="UIN"
     * 
     *  @ejb.persistence
     * 			table-name="GROUPS"
     * 
     *  @ejb.finder
     * 			query="SELECT OBJECT(g) FROM Group AS g"
     * 			signature="java.util.Collection findAllGroups()"
              NOTE: THIS FINDER IS NOT SENDING ANYTHING TO DATABASE.
     * 
     *  @ejb.interface
     *     		local-class="com.aa.samples.interfaces.GroupLocal"
     * 
     *  @ejb.home
     * 		 		local-class="com.aa.samples.interfaces.GroupLocalHome"
     * 
     *  @jboss.persistence 
     * 			datasource="java:/jdbc/dev01"  NOTE: JNDI name of the connection is "jdbc/dev01", as specified in "mysql-ds.xml" in JBoss deploy folder. I tried "java:jdbc/dev01" also - neither of the two works.
     * 			datasource-mapping="mySQL"
     * 			create-table="False"
     * 			remove-table="False"
     * 			table-name="GROUPS"
     * 
     */
    public abstract class GroupBean implements EntityBean {
      
      protected EntityContext etx;
      protected Logger logger =Logger.getLogger(GroupBean.class);
      
      /*
       * 1. Implementing Home interface
       */
      
      /**
       * @param name
       * @ejb.create-method
       */
      public Integer ejbCreate(String name, String description) throws CreateException {
      	BasicConfigurator.configure();
      	logger.debug("GroupBean.ejbCreate invoked.");
      	
      	if(name==null) {
      		throw new CreateException("name null");
      	}
      	
      	setName(name);
      	setDescription(description);
      	
      	return null;
      }
      
      public void ejbPostCreate(String name, String description) throws CreateException {
      	BasicConfigurator.configure();
      	logger.debug("GroupBean.ejbPostCreate invoked.");
      	
      	return;
      }
      
      /*
       * 2. Persistence methods:
       */  
      
      /**
       * @ejb.persistent-field
       * @ejb.persistence
       * 			column-name="UIN"
       * 			sql-type="INTEGER"
       * @ejb.pk-field
       * @ejb.interface-method
       */
      public abstract	Integer getUIN();
      
      /**
       * @ejb.interface-method
       */
      public abstract void setUIN(Integer UIN);
      
      /**
       * @ejb.persistent-field
       * @ejb.persistence
       * 			column-name="name"
       * 			sql-type="VARCHAR"
       * @ejb.interface-method
       */
      public abstract String getName();
      
      /**
       * @ejb.interface-method
       */
      public abstract void setName(String name);
      
      /**
       * @ejb.persistent-field
       * @ejb.persistence
       * 			column-name="description"
       * 			sql-type="VARCHAR"
       * @ejb.interface-method
       */
      public abstract String getDescription();
      
      /**
       * @ejb.interface-method
       */
      public abstract void setDescription(String description);
      
      /**
       * @ejb.persistent-field
       * @ejb.persistence
       * 			column-name="isSuspended"
       * 			sql-type="TINYINT"
       * @ejb.interface-method
       */
      public abstract Boolean getIsSuspended();
      
      /**
       * @ejb.interface-method
       */
      public abstract void setIsSuspended(Boolean isSuspended);
      
      
      /*
       * 3. Implementing EntityBean interface:
       */
      public void ejbRemove() throws RemoveException {
      	BasicConfigurator.configure();
      	logger.debug("GroupBean.ejbRemove invoked.");
      	
      	return;
      }  
      
      public void ejbLoad() {
      	BasicConfigurator.configure();
      	logger.debug("GroupBean.ejbLoad invoked.");
      	
      	return;
      }
    
      public void ejbStore() {
      	BasicConfigurator.configure();
      	logger.debug("GroupBean.ejbStore invoked.");
      	
      	return;
      }
    
      public void ejbActivate() {
      	BasicConfigurator.configure();
      	logger.debug("GroupBean.ejbActivate invoked.");
      	
      	return;
      }
    
      public void ejbPassivate() {
      	BasicConfigurator.configure();
      	logger.debug("GroupBean.ejbPassivate invoked.");
      	
      	return;
      }
    
      public void unsetEntityContext() {
      	BasicConfigurator.configure();
      	logger.debug("GroupBean.unsetEntityContext invoked.");
      	
      	etx= null;
      	
      	return;
      }
    
      public void setEntityContext(EntityContext etx) {
      	BasicConfigurator.configure();
      	logger.debug("GroupBean.setEntityContext invoked.");
    
      	this.etx= etx;
      	
      	return;
      }
      
    }

    3. SCREEN DUMP
    Code:
    ...
    ... lots of stuff...
    23:15:41,553 INFO  [RequestProcessor] Processing a 'POST' for path '/prepareLoginAction'
    23:15:48,368 INFO  [STDOUT] 461330 [http-0.0.0.0-8080-Processor25] DEBUG com.aa.samples.actions.PrepareLoginAction  - PrepareLoginAction invoked
    ERROR: invalid console appender config detected, console stream is looping23:15:53,559 INFO  [STDOUT] 466521 [http-0.0.0.0-8080-Processor25] DEBUG com.aa.samples.beans.GroupBean  - GroupBean.setEntityContext invoked.
    23:15:53,561 INFO  [STDOUT] 466521 [http-0.0.0.0-8080-Processor25] DEBUG com.aa.samples.beans.GroupBean  - GroupBean.setEntityContext invoked.
    23:15:53,566 INFO  [STDOUT] 466528 [http-0.0.0.0-8080-Processor25] DEBUG org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.GroupEJB#findAllGroups  - Executing SQL: SELECT t0_g.UIN FROM GROUPEJB t0_g
    23:15:53,568 INFO  [STDOUT] 466528 [http-0.0.0.0-8080-Processor25] DEBUG org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.GroupEJB#findAllGroups  - Executing SQL: SELECT t0_g.UIN FROM GROUPEJB t0_g
    
    ... nothing related to JDBC/exceptions...
    4. mysql-ds.xml

    I still haven't been able to get to the bottom of it. The only thing I know is that for sure my CMP "GroupBean" is sending nothing to target database. I used p6spy and intercepted anything to/from database.

    Code:
    <datasources>
      <local-tx-datasource>
        <jndi-name>jdbc/dev01</jndi-name>
        <connection-url>jdbc:mysql://127.0.0.1:3306/dev01</connection-url>
        <driver-class>com.p6spy.engine.spy.P6SpyDriver</driver-class>
        <user-name>someuser</user-name>
        <password>somepasswd</password>
      </local-tx-datasource>
    </datasources>
    5. XDoclet generated "jbosscmp--jdbc.xml" (NOTE: The datasource tag looks correct....)

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">
    
    <jbosscmp-jdbc>
       <defaults>
       </defaults>
       <enterprise-beans>
          <entity>
             <ejb-name>GroupEJB</ejb-name>
    		 <datasource>java:/jdbc/dev01</datasource>
    		 <datasource-mapping>mySQL</datasource-mapping>
    
             <table-name>GROUPS</table-name>
    
             <cmp-field>
                <field-name>UIN</field-name>
                <column-name>UIN</column-name>
            </cmp-field>
             <cmp-field>
                <field-name>name</field-name>
                <column-name>name</column-name>
            </cmp-field>
             <cmp-field>
                <field-name>description</field-name>
                <column-name>description</column-name>
            </cmp-field>
             <cmp-field>
                <field-name>isSuspended</field-name>
                <column-name>isSuspended</column-name>
            </cmp-field>
    
          </entity>
       </enterprise-beans>
    </jbosscmp-jdbc>

    Any idea? Thanks in advance!
    norm

  2. #2
    Join Date
    Feb 2004
    Posts
    19

    Spotted a problem, rectified it, but PROBLEM REMAINS

    First off, found a problem, rectified it, and BUT THE PROBLEM REMAINS:


    Code:
    ...
    context = new InitialContext();
    Object ref = context.lookup(groupJNDI); 
    home = (GroupLocalHome)PortableRemoteObject.narrow(ref, groupLocalHome.class); //GroupLocalHome is a LOCAL interface!
    ...
    groups=home.findAllGroups();
    ...
    So this error was rectified (BUT STILL PROBLEM REMAINS - MY BEAN IS SENDING NOTHING TO DATABASE!)

    Code:
    context = new InitialContext(); 
    GroupLocalHome home = (GroupLocalHome) context.lookup(groupJNDI); 
    ...
    groups=home.findAllGroups(); //I used p6spy to intercept database calls (trace SQL queries), and it show that nothing was sent to target database.
    ...
    Help!
    norm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links