users@glassfish.java.net

Re: Can't return Entity EJBs from a Remote EJB

From: <forums_at_java.net>
Date: Wed, 18 May 2011 10:12:28 -0500 (CDT)

Hi,

I'm having the same problem here. This is my setup:
The SessionBean:   
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
publicclass CalculateBean implements CalculateBeanRemote {

    @PersistenceContext(unitName = "CalculationJPA")
    private EntityManager em;

    @Override
    public Result getResult(Integer id) {      
        Result result= em.find(Result.class, id);    
        //Checked here:   result has an resultId and a resultName,
they are not null
        return result;
    }
}
The RemoteInterface:
@Remote
public interface CalculateBeanRemote {
    public Result getResult(Integer id);
}
The Entity:
@Entity
@Table(name = "Result")
public class Result implements Serializable{
   
    @Id
    private Integer resultId;
   
    @Column(nullable = false, length = 800)
    private String resultName;
   
    public Result() {
    }
    public Result(Integer id, String name) {
        super();
        this.resultId= id;
        this.resultName= name;
    }
    //getters and setters
}
In my Servlet:
    Context context = getInitialContext();
    CalculateBeanRemote calculator = (CalculateBeanRemote)
   
context.lookup("java:global/TestEjbEnterpriseApplication/TestEjbEnterpriseApplication-ejb/CalculateBean!com.mycompany.jee.ejb.CalculateBeanRemote");
    Result result = calculator.getResult(new Integer(9)); //Here I receive
a Result with null resultId and null resultName
   
My persistence.xml
  <persistence-unit name="CalculationJPA" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.itcan.jee.ejb.model.Insurance</class>
    <properties>
      <property name="javax.persistence.jdbc.url"
value="jdbc:derby://localhost:1527/sample"/>
      <property name="javax.persistence.jdbc.password" value="app"/>
      <property name="javax.persistence.jdbc.driver"
value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.user" value="app"/>
    </properties>
  </persistence-unit>

So, the fields in the result are set in CalculateBean, but in my servlet I
receive null-fields.

I have done the same example but without setting my Result class to being an
Entity, and there it works normally.

So the problem seems that the Entity is not returned correctly to the client.

Can anybody help?

Thank you in advance!

Regards


--
[Message sent by forum member 'MohamzJava']
View Post: http://forums.java.net/node/794504