musicBean.javapackage music.ejb;import java.rmi.RemoteException;import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import java.util.Collection;/**
* @ejb.bean name="Music"
*           display-name="Name for Music"
*           description="Description for Music"
*           jndi-name="ejb/Music"
*           type="CMP"
*           cmp-version="2.x"
*           view-type="local"
*           primkey-field = "content"
* @ejb.persistence table-name = "musicnews" read-only = "false"
* @jboss.persistence create-table = "true" remove-table = "false" datasource = "java:MySqlDS" datasource-mapping = "mySQL"    
* @ejb.finder signature = "Collection findAll()" unchecked = "true" query = "select object(g) from Music g" 
*   
*/
public abstract class MusicBean implements EntityBean {        public MusicBean() {
                super();
                // TODO 自动生成构造函数存根
        }
        private EntityContext etx;
        public void setEntityContext(EntityContext ctx)
                throws EJBException,
                RemoteException {
                etx = ctx;
                // TODO 自动生成方法存根        }        public void unsetEntityContext() throws EJBException, RemoteException {
                // TODO 自动生成方法存根        }        public void ejbRemove()
                throws RemoveException,
                EJBException,
                RemoteException {
                // TODO 自动生成方法存根        }        public void ejbActivate() throws EJBException, RemoteException {
                // TODO 自动生成方法存根        }        public void ejbPassivate() throws EJBException, RemoteException {
                // TODO 自动生成方法存根        }        public void ejbLoad() throws EJBException, RemoteException {
                // TODO 自动生成方法存根        }        public void ejbStore() throws EJBException, RemoteException {
                // TODO 自动生成方法存根        }        /**
         * Create method
         * @ejb.create-method  view-type = "local"
         */
        public String ejbCreate(String content, int flag, int newsid)
                throws javax.ejb.CreateException {
                // TODO Auto-generated method stub
                System.out.println("ejbCreate0...");
                setContent(content);
                setFlag(flag);
                setNewsid(newsid);
                System.out.println("ejbCreate1...");
                return content;
        }
        /**
         * Post Create method
         */
        public void ejbPostCreate(String content, int flag, int newsid)
                throws javax.ejb.CreateException {
                // TODO Auto-generated method stub
        }
        /**
         * Getter for CMP Field newsid
         *
         * @ejb.pk-field
         * @ejb.persistent-field
         * @ejb.interface-method   view-type="local"
         */
        public abstract int getNewsid();        /**
         * Setter for CMP Field newsid
         *
         * @ejb.interface-method   view-type="local"
         */
        public abstract void setNewsid(int value);        /**
         * Getter for CMP Field content
         *
         * 
         * @ejb.persistent-field
         * @ejb.interface-method   view-type="local"
         */
        public abstract String getContent();        /**
         * Setter for CMP Field content
         *
         * @ejb.interface-method   view-type="local"
         */
        public abstract void setContent(String value);        /**
         * Getter for CMP Field flag
         *
         * 
         * @ejb.persistent-field
         * @ejb.interface-method   view-type="local"
         */
        public abstract int getFlag();        /**
         * Setter for CMP Field flag
         *
         * @ejb.interface-method   view-type="local"
         */
        public abstract void setFlag(int value);        /**         
         * @ejb.create-method
         * @return 
         *           
         */
        
        
        
        public String ejbCreate() throws javax.ejb.CreateException {
                System.out.println("ejbCreate...");
                // TODO Auto-generated method stub
                return null;
        }
        /**
         * Post Create method
         */
        public void ejbPostCreate() throws javax.ejb.CreateException {                // TODO Auto-generated method stub
        }        /**
         * Business method
         * @ejb.interface-method  view-type = "local"
         */
        public String busstest() {
                // TODO Auto-generated method stub
                return null;
        }
        }
MusicLocalHome.java
/*
* Generated by XDoclet - Do not edit!
*/
package music.interfaces;/**
* Local home interface for Music.
*/
public interface MusicLocalHome
   extends javax.ejb.EJBLocalHome
{
   public static final String COMP_NAME="java:comp/env/ejb/MusicLocal";
   public static final String JNDI_NAME="MusicLocal";   public music.interfaces.MusicLocal create(java.lang.String content , int flag , int newsid)
      throws javax.ejb.CreateException;   public music.interfaces.MusicLocal create()
      throws javax.ejb.CreateException;   public java.util.Collection findAll()
      throws javax.ejb.FinderException;   public music.interfaces.MusicLocal findByPrimaryKey(java.lang.String pk)
      throws javax.ejb.FinderException;}musicLocal.java
/*
* Generated by XDoclet - Do not edit!
*/
package music.interfaces;/**
* Local interface for Music.
*/
public interface MusicLocal
   extends javax.ejb.EJBLocalObject
{
   /**
    * Getter for CMP Field newsid
    */
   public int getNewsid(  ) ;   /**
    * Setter for CMP Field newsid
    */
   public void setNewsid( int value ) ;   /**
    * Getter for CMP Field content
    */
   public java.lang.String getContent(  ) ;   /**
    * Setter for CMP Field content
    */
   public void setContent( java.lang.String value ) ;   /**
    * Getter for CMP Field flag
    */
   public int getFlag(  ) ;   /**
    * Setter for CMP Field flag
    */
   public void setFlag( int value ) ;   /**
    * Business method
    */
   public java.lang.String busstest(  ) ;}

解决方案 »

  1.   

    home.create(); 
    程序到这儿的时候出错,而本身,create()并没有添加任何的代码.
      

  2.   

    呵呵,我不是高手,
    给你推荐一个 JAVA高手Q群 18349943
      

  3.   

    是这样的无论你的ejbCreate有没有添加代码,只要执行ejbCreate 那么cmp就认为数据库中需要增加一条记录,而你的cmp中这个create什么也没做,当然保错误了
    你可以试验修改为:
    public String ejbCreate()
                    throws javax.ejb.CreateException {
                    // TODO Auto-generated method stub
                    System.out.println("ejbCreate0...");
                    setContent("11");
                    setFlag(12);
                    setNewsid(13);
                    System.out.println("ejbCreate1...");
                    return content;
            }但是只能自行执行一次,因为相应的记录已经创建了
      

  4.   

    这里面没什么高手太让我失望了,我的问题还是让我来解决吧,为了各位不让这种问题困扰
    原文地址http://www.jboss.com/?module=bb&op=viewtopic&p=3882728
    1] Edit conf/jboss-service.xml and make CallByvalue as 'true' in NamingService as below <mbean code="org.jboss.naming.NamingService" 
    name="jboss:service=Naming" 
    xmbean-dd="resource:xmdesc/NamingService-xmbean.xml"> 2] Edit deploy/ear-deployer.xml, and set Isloated and CallByvalue as true 3]Edit deploy\jbossweb-tomcat55.sar\META-INF\jboss-service.xml , and set Java2ClassLoadingCompilance and UseJbossWebLoader attributes as false 有的时间可能需要调整
    Java2ClassLoadingCompilance and UseJbossWebLoader attributes as true才能正确执行,你应当根据你的程序来测试调整一下就可以了