Finally I could get a CMP example working on JBOSS + ECLIPSE + JBOSS-IDE + XDOCLET 

I wanted to share the example with all of you.

package product.ejb;

import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.CreateException;

import org.apache.log4j.Category;

import javax.ejb.RemoveException;
import javax.ejb.EJBException;
/**
 * @ejb.bean name="Product"
 *                       
 *           display-name="Product Bean"
 *           description="Entity Bean For Product Schema"
 *           jndi-name="ejb/Product"
 *           type="CMP"
 *           cmp-version="2.x"
 *           view-type="remote"
 *                       primkey-field= "id"
 *                      
 * 
 * 
 * @ejb.finder
 *                      signature = "Product findByPrimaryKey(java.lang.Integer id)"
 *                      query = "Select Object(P) from Product P where P.id=?1"
 *                      transaction-type="NotSupported"
 * 
 * @ejb.finder
 *                      signature="java.util.Collection findAll()"
 *                      query="Select Object(P) from Product P" 
 *                      transaction-type="NotSupported"
 * 
 * @jboss-query
 *                      signature="Product findByPrimaryKey(java.lang.Integer id)"
 *                      query="Select Object(P) from Product P where P.id=?1"
 * 
 * @jboss-query
 *                      signature="Collection findAll()"
 *                      query="Select Object(P) from Product P"
 * 
 * @ejb.persistence
 *                      table-name="products"
 *                      
 * 
 *
 */
public abstract class ProductBean implements EntityBean {
        
        //The entity bean lifeline
        private EntityContext ctx;
        
        //Tell your vows to this logger
        private Category log = Category.getInstance(getClass());
        
        /**
         * @throws CreateException
         * @ejb.create-method
         */
        public Integer ejbCreate(Integer id, String name, Double price)
                                                throws CreateException
        {
        
                log.info("Adding product type <" + name + "> to database");
                setId(id);
                setName(name);
                setPrice(price);
                return null;
        }
        
        public void ejbPostCreate(Integer id, String name, Double price)
                                        throws CreateException
                        
        {
                
        }
        
        /**
         * 
         * @ejb.interface-method
         * @ejb.persistence-field
         * @ejb.pk-field
         * @ejb.persistence column-name="id"
         *                                      jdbc-type="INTEGER"
         *                                      sql-type="INTEGER"
         */
        
          public abstract Integer getId();
          public abstract void setId(Integer id);
          
         
          /**
           [EMAIL PROTECTED]
           [EMAIL PROTECTED]
           [EMAIL PROTECTED] column-name="name"
           *                             jdbc-type="VARCHAR"
           *                             sql-type = "VARCHAR(50)"
           */
           
           public abstract String getName();
           public abstract void setName(String s);
           
           /**
            [EMAIL PROTECTED]
            [EMAIL PROTECTED]
            [EMAIL PROTECTED] column-name="price"
            *                             jdbc-type="DOUBLE"
            *                             sql-type="DOUBLE" 
            */
            public abstract Double getPrice();
            public abstract void setPrice(Double price);
         
        
            public void ejbRemove() throws RemoveException, EJBException
                {
                log.info("Remove :" + getName());
                }
            
            public void setEntityContext(EntityContext ctx)
            {
                this.ctx = ctx;
            }
            
            public void unsetEntityContext()
            {
                ctx=null;
            }
            
            public void ejbActivate(){}
            
            public void ejbPassivate(){}
            
            public void ejbLoad(){}
            
            public void ejbStore(){}

            
            
}

Hope this will help new-bies.

My heartful thanks to JBOSS development team.

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3849843#3849843

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3849843


-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to