-
1. Re: JBoss 3.2.x, MySQL and CMP
kv_moj Aug 21, 2003 3:38 AM (in response to rberehoudougou)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
hassanz Aug 21, 2003 7:09 AM (in response to rberehoudougou)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
rberehoudougou Aug 21, 2003 12:23 PM (in response to rberehoudougou)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
hassanz Aug 21, 2003 1:18 PM (in response to rberehoudougou)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
rberehoudougou Aug 21, 2003 2:17 PM (in response to rberehoudougou)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
rberehoudougou Aug 25, 2003 3:07 AM (in response to rberehoudougou)Anybody who can help with this ?
Thanks. -
7. Re: JBoss 3.2.x, MySQL and CMP
cepage Aug 25, 2003 12:06 PM (in response to rberehoudougou)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
kv_moj Aug 27, 2003 6:35 AM (in response to rberehoudougou)
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 Aug 28, 2003 8:52 PM (in response to rberehoudougou)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.