users@glassfish.java.net

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

From: emiddio-frontier <emiddio_at_frontier.com>
Date: Wed, 18 May 2011 09:26:59 -0700

i have seen where (just yesterday) the jdbc url doesnt work with glassfish
as i would have expected,

if i use something similiar to
<jta-data-source>jdbc/__default</jta-data-srouce>
added to the persistence.xml instead -- then things work.

gary



----- Original Message -----
From: <forums_at_java.net>
To: <users_at_glassfish.java.net>
Sent: Wednesday, May 18, 2011 8:12 AM
Subject: Re: Can't return Entity EJBs from a Remote EJB


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