[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - JPA Entity attached scope?
Sanjuro
do-not-reply at jboss.com
Tue Jan 6 12:45:31 EST 2009
Hi,
I'm using JBoss 5.0 with JPA for storing my data in a database. However at some point in my code my entities become detached from the persistence context when passing them to a different class.
When exactly do entities get detached? Outside the method scope they were created in? Outside the class? Outside the JAR file they were created in? Or maybe when traversing a remote interface?
More specific: I have an entity which looks like this:
| @Entity
| public class Customer implements java.io.Serializable {
| @Id
| private Long Id;
| private String firstName;
| [...]
| }
|
And a interface to retrieve the entity:
| @Remote
| public interface CustomerDBAO {
| public Customer get(Long customerId);
| [...]
| }
|
And of course a EJB to implement the interface:
| @Stateless
| public class CustomerDBAOBean implements CustomerDBAO {
| public Customer get(Long customerId) {
| return em.find(Customer.class, customerId);
| }
| [...]
| }
|
All three are in data.jar. Then in ejb.jar with a class which retrieves the entity:
| @Stateless
| public class CustomerFacadeBean {
| @EJB
| CustomerDBAO customerDBAO;
| [...]
| }
|
In the CustomerFacadeBean the Customer entity is detached. What do I need to change to make sure the entity stays attached? Put all classes in the same package? Change to a local interface? Or move the method to the CustomerDBAO class?
Thanks
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4199852#4199852
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4199852
More information about the jboss-user
mailing list