JBoss Community

Re: Entity hashCode and equals overriding

created by fabio valsecchi in EJB3 Development - View the full discussion

The cart variable is inside the CartBean:

-----------------------------------------------------------------------

@Stateful

@Remote(ICart.class)

public class CartBean implements ICart {

          @PersistenceContext(unitName = "JPABOOK", type=PersistenceContextType.EXTENDED)

    EntityManager entityManager;

          private Cart cart = null;

 

    public CartBean() {}

   

    @Override

    public void create(String username) {

              cart = entityManager.find(Cart.class, username);

    

        if (cart == null) {

                  cart = new Cart();

                  cart.setUsername(username);

                  cart.setBill(0);

                  entityManager.persist(cart);

        }

    }

    @Override

    public void addArticle(Book book, Integer quantity) {

              Integer currentQuantity = cart.getArticles().get(book);

   

              System.out.println(currentQuantity);

    

        if (currentQuantity == null) {

                  currentQuantity = 0;

        }

        currentQuantity += quantity;

        cart.getArticles().put(book, currentQuantity);

    }

-----------------------------------------------------------------------

 

The cart it could be empty or containg some entries.

Reply to this message by going to Community

Start a new discussion in EJB3 Development at Community