[jboss-user] [EJB 3.0] - Re: EntityManager not auto-flushing at end of SLSB method
lpmon
do-not-reply at jboss.com
Wed Jan 2 23:24:59 EST 2008
I decided to post the code. I just saw your comment about the "new entity ..." and that does explain part of it (purchase not saved ) as you will see. That does not explain why the changed entity (member) did not get saved. Member was injected in the calling SLSB using SEAM and passed to this method.
If it is true that a new entity is not saved on exit that needs to be emphasized in documentation. I started with the trailblazer and use the references. Maybe it is in there but I never noticed it.
public @Stateless class PurchaseCreditsBean implements PurchaseCredits {
@PersistenceContext
EntityManager em;
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void purchaseCredits(Member member, int purchaseQty)
{
Purchase purchase = new Purchase();
purchase.setPurchasedCredits(purchaseQty);
member.setCredits(purchaseQty + member.getCredits());
purchase.setMember(member);
purchase.setPurchasedCredits(purchaseQty);
em.merge(purchase); // TODO should not have to call merge
em.merge(member);
}
}
Thanks, my assumption is the SEAM injected entity is behaving as if it is not attached to my em as well. If this is the case I certainly misunderstood this. I bet many others have been down this same path!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4116598#4116598
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4116598
More information about the jboss-user
mailing list