Solved

Configuration Database connecton for CMP

Posted on 2006-11-19
12
403 Views
Last Modified: 2013-11-24
I'm newbie in EJB. Now I'm writing an EJB project. I use JBuilder 2006 and JBoss 4.0 for writing my project with CMP Entity Bean. I try many time but can't connect to database. I use Mysql database, connected by MySql JDBC over DataSource. Pls help me, is there need any configuraton?
0
Comment
Question by:arobe12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 10

Expert Comment

by:mbvvsatish
ID: 17977423
first try deploying this example
http://www.kylev.com/code/jboss-mysql-and-cmp/
0
 
LVL 10

Expert Comment

by:mbvvsatish
ID: 17977429
here is how you set up a mysql datasource in jboss
http://wiki.jboss.org/wiki/Wiki.jsp?page=SetUpAMysqlDatasource
0
 
LVL 5

Expert Comment

by:deeppra
ID: 17977436
send me what error u r getting??
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:arobe12
ID: 17977480
I can lookup my EJB, but can't connect to database, here is error message that apperes when I run Client test Bean:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
      java.rmi.ServerException: RuntimeException; nested exception is:
      java.lang.IllegalStateException: createBeanClassInstanceCommand == null
0
 
LVL 10

Expert Comment

by:mbvvsatish
ID: 17977498
looks like a NullPointerException.
can you post the bean code along with you deployment descriptor xml's.
0
 

Author Comment

by:arobe12
ID: 17977514
This is Bean Code

//////////////////////////////////

package testproject;

import java.sql.*;
import java.util.Properties;
import java.util.Enumeration;
import java.util.Vector;
import java.rmi.RemoteException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.ObjectNotFoundException;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;

public class CMPProductBean implements EntityBean {

  EntityContext context;

  public String productId;
  public String productName;
  public String description;
  public double price;

  public String getProductId() {
    System.out.println("getProductId");
    return productId;
  }

  public String getProductName() {
    System.out.println("getProductName");
    return productName;
  }

  public String getDescription() {
    System.out.println("getDescription");
    return description;
  }
  public double getPrice() {
    System.out.println("getPrice");
    return price;
  }

  public String ejbCreate(int productId, String productName,
    String description, double price)
    throws RemoteException, CreateException {
    System.out.println("ejbCreate");
    this.productId = Integer.toString( productId);
    this.productName = productName;
    this.description = description;
    this.price = price;
    return Integer.toString(productId);
  }

  public void ejbPostCreate(int productId, String productName,
    String description, double price)
    throws RemoteException, CreateException {
    System.out.println("ejbPostCreate");
  }

  public void ejbRemove() throws RemoteException {
    System.out.println("ejbRemove");
  }

  public void ejbActivate() {
    System.out.println("ejbActivate");
  }

  public void ejbPassivate() {
    System.out.println("ejbPassivate");
  }

  public void ejbLoad() {
    System.out.println("ejbLoad");
  }
  public void ejbStore() {
    System.out.println("ejbStore");
  }
  public void setEntityContext(EntityContext context) {
    System.out.println("setEntityContext");
    this.context = context;

  }

  public void unsetEntityContext() {
    System.out.println("unsetEntityContext");
    context = null;
  }
}

/////////////////////////////////////////////////////////////////

This is xml file:

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

<ejb-jar>
  <display-name>HelloCMP</display-name>
  <enterprise-beans>
    <entity>
      <ejb-name>CMPProduct</ejb-name>
      <home>testproject.CMPProductHome</home>
      <remote>testproject.CMPProduct</remote>
      <ejb-class>testproject.CMPProductBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      <reentrant>False</reentrant>
      <cmp-field>
        <field-name>productId</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>productName</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>description</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>price</field-name>
      </cmp-field>
      <primkey-field>productId</primkey-field>
      <resource-ref>
        <res-ref-name>jdbc/DataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
      </resource-ref>
    </entity>
  </enterprise-beans>
  <assembly-descriptor>
    <container-transaction>
      <method>
        <ejb-name>CMPProduct</ejb-name>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
  </assembly-descriptor>
</ejb-jar>
0
 
LVL 10

Expert Comment

by:mbvvsatish
ID: 17977523
i am looking for jbosscmp-jdbc.xml please post it here
0
 

Author Comment

by:arobe12
ID: 17977558
Here is jbosscmp-jdbc.xml file

<?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>
    <datasource>DataSource</datasource>
    <datasource-mapping>Hypersonic SQL</datasource-mapping>
  </defaults>
  <enterprise-beans>
    <entity>
      <ejb-name>CMPProduct</ejb-name>
      <table-name>product</table-name>
      <cmp-field>
        <field-name>productId</field-name>
        <column-name>PRODUCT_ID</column-name>
      </cmp-field>
      <cmp-field>
        <field-name>productName</field-name>
        <column-name>PRODUCT_NAME</column-name>
      </cmp-field>
      <cmp-field>
        <field-name>description</field-name>
        <column-name>DESCRIPTION</column-name>
      </cmp-field>
      <cmp-field>
        <field-name>price</field-name>
        <column-name>PRICE</column-name>
      </cmp-field>
    </entity>
  </enterprise-beans>
</jbosscmp-jdbc>

0
 
LVL 10

Accepted Solution

by:
mbvvsatish earned 500 total points
ID: 17977627
>> <datasource>DataSource</datasource>
>> <datasource-mapping>Hypersonic SQL</datasource-mapping>

change the above lines in jbosscmp-jdbc.xml to the following

<datasource>java:/DataSource</datasource>
<datasource-mapping>MySql</datasource-mapping>
where DataSource is the name of the datasource that you created for mysql
0
 

Author Comment

by:arobe12
ID: 17977689
Succeful but it appears new error:

javax.ejb.CreateException: Error checking if entity exists:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'PRODUCT_ID' in 'where clause'
0
 

Author Comment

by:arobe12
ID: 17977700
I see the problem. Thanks for your help.
0
 
LVL 10

Expert Comment

by:mbvvsatish
ID: 17977716
check whether you have declared the 'PRODUCT_ID' as an auto_increment column in the mysql database.
if so you need to change your deployment descriptors.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 85
ejb message driven bean mdb creation steps 2 50
Bot application - advice 3 79
Eclipse with various Java releases 7 84
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question