[jboss-user] [EJB 3.0] - Share entity bean between stateless session beans
kstrunk
do-not-reply at jboss.com
Tue Nov 18 16:01:48 EST 2008
Hi!
I have a problem with two local stateless session beans and an EntityManager which is used in one of the SLSBs.
I want the first SLSB to do basic database operations like finding entities and the other one to work with the resulting entities. I attached a small example:
@Stateless
public class Bean1 {
@PersistenceContext(unitName = "UnitName")
protected EntityManager entityManager;
public Entity findEntity(...) {
...
}
}
@Stateless
public class Bean2 {
@EJB
private Bean1 bean1;
public User doSomething(...) {
Entity entity = bean1.findEntity();
entity.setAnything();
}
}
My problem is that the entity in method doSometing of Bean2 gets detached. So any changes of the entity bean (by calling the setter) are not transacted to database.
Is this behaviour correct? Is there any way to use a managed entity bean in both SLSBs so that I can use the entity in bean2 the same way as in bean1?
Hope someone here can help me!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4190256#4190256
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4190256
More information about the jboss-user
mailing list