class Test
{
    void change(StringBuffer a)
    {
         a.append("hehe");
    }
    public static void main(String[] args)
    {
        StringBuffer b=new StringBuffer("haha");
        Test t= new Test();
        t.change(b);
        System.out.println(b);
    }
}
运行后,打印 hahahehe
但是在EJB 3.0 中
//RoleControl.java
-----------------------------------------------------------
package com.shitong.authority;public interface RoleControl 
{
boolean QueryDefaultRole(StringBuffer xmlstring);
}
------------------------------------------------------------//RoleControlBean.java
-----------------------------------------------------------
package com.shitong.authority.imp;import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import java.util.*;
import com.shitong.authority.*;
import java.io.*;@Stateless
@Remote ({RoleControl.class})
@Local ({RoleControl.class})
public class RoleControlBean implements RoleControl
{
         public boolean QueryDefaultRole(StringBuffer xmlstring)
{
               xmlstring.append("hehe");
               return true;
         }
}
-----------------------------------------------------------//RoleControlBeanClient
-----------------------------------------------------------
package com.shitong.authority.imp;
import com.shitong.authority.*;
import java.util.Properties;
import javax.naming.InitialContext;
public class RoleControlBeanClient 
{

public static void main(String[] args)
{
Properties props = new Properties();
props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "localhost:1099");
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
try 
{
InitialContext ctx = new InitialContext(props);
RoleControl role = (RoleControl) ctx.lookup("RoleControlBean/remote");
                           StringBuffer sXmlString=new StringBuffer("haha");
role.QueryDefaultRole(sXmlString);
System.out.println(sXmlString);
}
catch (Exception e) 
{
System.out.println(e.getMessage());
}
}
}运行后,结果还是haha,不是hahahehe
先谢谢大家了。

解决方案 »

  1.   

    EJB的调用采用值传递方式,所以它不会改变你原来的对象(sXmlString)的值
      

  2.   

    那个好郁闷哦。我要boolean,int这些类型的值,不痛苦死了啊。
      

  3.   

    肯定要返回才行嘛,EJB多用于分布式应用,不是一个jvm不可能传引用
      

  4.   

    唉,不是NO EJB了吗?怎么还有人用EJB啊
      

  5.   

    EJB 3.0 的O/R映射,是一种时代的进步,我们不用再关心数据库部分了,不用写jdbc了,是个了不起的进步,我学了这么久,发现这个才是技术革新的东西,EJB 3.0的确值得你去一学。