9 Replies Latest reply on Aug 28, 2003 8:52 PM by ergomy

    JBoss 3.2.x, MySQL and CMP

    Raphael BEREHOUDOUGOU Newbie

      Hi All,
      I have probably a " basic" issue using JBoss. I am new to it so..
      I have deployed a CMP on Jboss. I configured JBoss to use MySQL database . Everything seem fine.
      When I run my client, I can create instances of the CMP. The only thing that is Strange is, when I go back to MySQL, there is no row entry in the database !
      The same client run on WebSphere 5 does update my database immediatly.
      Can someone explain to me what the problem is ? I suspect JBoss is still using hypersonic !!??

      Regards
      The configuration for MySQL uses the example mysql-ds.xml provided with the binary distribution.
      Thanks for your help

        • 1. Re: JBoss 3.2.x, MySQL and CMP
          Kayvan Mojarrad Newbie

          Hi,

          What about your defaults in jbosscmp-jdbc.
          It's possible that the defaults are set to use the defaultDS which is a hsql datasource.

          If you haven't already done this then add the following to your jbosscmp-jdbc.xml:

          <jbosscmp-jdbc>

          java:/yourDS
          <datasource-mapping>mySQL</datasource-mapping>

          .....
          .....

          .....
          .....

          .....
          </jbosscmp-jdbc>

          kv.

          • 2. Re: JBoss 3.2.x, MySQL and CMP
            Hassan Newbie

            It seems like your data source is not configured. Go to your jmx-console.
            http://localhost:port/jmx-console
            and check if your datasource is configured properly.
            (it will be under jboss.jca)

            -hassan

            • 3. Re: JBoss 3.2.x, MySQL and CMP
              Raphael BEREHOUDOUGOU Newbie

              Here is my settings in standardjbosscmp-jdbc.xml

              java:/MySQLDataSource
              <datasource-mapping>mySQL</datasource-mapping>


              In jmx-console , I have the following :
              name=MySQLDataSource,service=LocalTxCM
              name=MySQLDataSource,service=ManagedConnectionFactory
              name=MySQLDataSource,service=ManagedConnectionPool

              Still the mySQl database is not updated !
              Thanks again.

              • 4. Re: JBoss 3.2.x, MySQL and CMP
                Hassan Newbie

                Seems like you are doing everything fine and your data sources are initializing.

                Can you post some code for your ejbs.

                Thanks,

                Hassan

                • 5. Re: JBoss 3.2.x, MySQL and CMP
                  Raphael BEREHOUDOUGOU Newbie

                  Ok, It is just a basic bean to test JBoss and mySQL
                  The Table Fields
                  stateCode Type VARCHAR (String) primary Key
                  taxRate Type float

                  the Bean :
                  public interface Tax extends EJBObject
                  {
                  public String getStateCode() throws RemoteException;
                  public float getTaxRate() throws RemoteException;
                  public void setTaxRate(float taxRate) throws RemoteException;
                  }

                  public interface TaxHome extends EJBHome
                  {
                  public Tax create(String stateCode, float taxRate) throws RemoteException, CreateException;
                  public Tax findByPrimaryKey(String primaryKey) throws RemoteException, FinderException;
                  public Collection findInRange(float lowerLimit,float upperLimit) throws RemoteException,FinderException;
                  }


                  public class TaxEJB implements EntityBean
                  {
                  EntityContext entityContext;
                  public String stateCode;
                  public float taxRate;
                  public String ejbCreate(String stateCode, float taxRate) throws CreateException
                  {
                  if (stateCode == null) {
                  throw new CreateException("The State Code is required.");
                  }
                  this.stateCode = stateCode;
                  this.taxRate = taxRate;
                  return null;
                  }
                  public void ejbPostCreate(String stateCode, float taxRate) throws CreateException
                  {
                  }
                  public void ejbLoad()
                  {
                  if (stateCode != null)
                  stateCode.trim();
                  }
                  public void ejbStore()
                  {
                  }
                  public void ejbRemove() throws RemoveException
                  {
                  }
                  public void ejbActivate()
                  {
                  }
                  public void ejbPassivate()
                  {
                  }
                  public void setEntityContext(EntityContext entityContext)
                  {
                  this.entityContext = entityContext;
                  }
                  public void unsetEntityContext()
                  {
                  entityContext = null;
                  }
                  public String getStateCode()
                  {
                  return stateCode;
                  }
                  public float getTaxRate()
                  {
                  return taxRate;
                  }
                  public void setTaxRate(float taxRate)
                  {
                  this.taxRate = taxRate;
                  }
                  }


                  The Client :

                  public class TaxClient
                  {
                  public static void main(String[] args)
                  {
                  try
                  {
                  Context initial = /*getWebSphereContextInfo();*/getJBossContextInfo();//new InitialContext();
                  Object objRef = initial.lookup("TaxBean");

                  TaxHome home = (TaxHome) PortableRemoteObject.narrow(objRef,
                  TaxHome.class);

                  Tax tax = null;

                  tax = home.create("IL",5.00f);
                  tax = home.create("CA",6.25f);
                  tax = home.create("FL",8.50f);
                  tax = home.create("CO",6.75f);

                  tax = home.findByPrimaryKey("CA");
                  System.out.println("CA tax rate : " + tax.getTaxRate());

                  System.out.println("Changing tax rate for CA state");
                  tax.setTaxRate(8.25f);

                  System.out.println("New CA tax rate: " + tax.getTaxRate());




                  Collection taxArray = home.findInRange(5.0f,7.0f);

                  Iterator it = taxArray.iterator();

                  while(it.hasNext())
                  {
                  Object objRef2 = it.next();
                  tax = (Tax)PortableRemoteObject.narrow(objRef2,
                  Tax.class);

                  System.out.println("Tax Rate in " + tax.getPrimaryKey() + " : " + tax.getTaxRate());

                  tax.remove();
                  }
                  }
                  catch (Exception ex)
                  {
                  ex.printStackTrace();
                  }
                  }

                  private static Context getJBossContextInfo()
                  {
                  Context ctx = null;
                  try
                  {
                  Properties prop = new Properties();
                  prop.put(Context.INITIAL_CONTEXT_FACTORY,
                  "org.jnp.interfaces.NamingContextFactory");

                  prop.put(Context.PROVIDER_URL, "Pendjari:1099");
                  prop.put("java.naming.factory.url.pkgs",
                  "org.jboss.naming:org.jnp.interfaces");

                  ctx = new InitialContext(prop);

                  }
                  catch (Exception ex)
                  {

                  }
                  return ctx;
                  }

                  private static Context getWebSphereContextInfo()
                  {
                  Context ctx = null;
                  try
                  {
                  Properties prop = new Properties();
                  prop.put(Context.INITIAL_CONTEXT_FACTORY,
                  "com.ibm.websphere.naming.WsnInitialContextFactory");

                  prop.put(Context.PROVIDER_URL, "iiop://localhost");
                  // "iiop://localhost:2809"

                  ctx = new InitialContext(prop);
                  }
                  catch (Exception ex)
                  {

                  }
                  return ctx;
                  }

                  }

                  Thanks

                  • 6. Re: JBoss 3.2.x, MySQL and CMP
                    Raphael BEREHOUDOUGOU Newbie

                    Anybody who can help with this ?
                    Thanks.

                    • 7. Re: JBoss 3.2.x, MySQL and CMP
                      Corby Page Newbie

                      Wrap your code in a transaction.begin() and transaction.commit().

                      If this fixes the problem, then you need to modify the transaction attributes in your deployment descriptor.

                      • 8. Re: JBoss 3.2.x, MySQL and CMP
                        Kayvan Mojarrad Newbie


                        You have a lot of code here where you're catching exceptions and doing nothing with them.
                        Try printing the stack trace of these so you can get an idea why no rows are created.

                        • 9. Re: JBoss 3.2.x, MySQL and CMP
                          ergomy Newbie

                          Something I learned when upgrading from jboss 2.4 to 3.2 using mysql was that the jdbc mapping for the java-type java.lang.object had to use a BLOB jdbc-type rather than JAVA_OBJECT (which had worked on jboss 2.4). I learned of this through the jboss dev maillist.

                          You should get an exception when attempting to store but your code might not be spewing the message.