Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3351340
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:53:49+00:00 2026-05-18T01:53:49+00:00

i have trouble with JPQL statement, i created NameQuery followed: @NamedQuery(name = Cart.findExistCart, query

  • 0

i have trouble with JPQL statement, i created NameQuery followed:

 @NamedQuery(name = "Cart.findExistCart", query = "SELECT c FROM Cart c WHERE  c.cartPK.userid = :userid AND c.cartPK.itemid = :itemid "),

in stateless bean i create one method to active this query followed:

 public Cart getUserItemCart(int userid,int itemid){

         Query query = em.createNamedQuery("Cart.findExistCart");
        // query.setParameter("userid", userid);
         query.setParameter("itemid", itemid);
         query.setParameter("userid", userid);

         return (Cart) query.getSingleResult();

     }

after that in JSF Managed Bean i create one method test if user id and item id are exist in DB it will print user id and itemid to server:

public void addtoCart(Items item){
        this.items = item;
        int userid = getMemberLoginController().getUser().getUserid().intValue();
        int itemid = getItems().getItemid().intValue();
        if (cartDAO.getUserItemCart(userid, itemid) != null ){


              // cart = cartDAO.getUserItemCart(userid, itemid);
               cartPk.setUserid(userid);
               cartPk.setItemid(itemid);
               cart.setCartPK(cartPk);
               cart = cartDAO.getUserItemCart(userid, itemid);

               System.out.println(cart.getCartQuantity());


    }

but when client add item A into db and then add item B into db, and once again add item A into DB , it don’t print item id of item id, it print item id of item B. Why?
if i create select statement findByItemid, it work well if i do upon requirement it mean when click add A then click add B , and add A again it print id 1-2-1, but if i use select statement find Cart by ItemId and UserId it not work, it will print itemid is 1-2-2
What’s happen with it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:53:49+00:00Added an answer on May 18, 2026 at 1:53 am

    you can delete 2 line

           cartPk.setUserid(userid);
           cartPk.setItemid(itemid);
    

    i think when you assign cart = cartDAO.getUserItemCart(userid, itemid);

    the userid and itemid are have value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble to convert from decimal to hex. Here is my code: select
i have trouble with following sql-statement (trimmed): SELECT nr, (CASE WHEN SUM(vkdtab.amount*liter)<>0 AND jjjjmm
I have trouble to parse and show events from Bands in Town´s API in
I have trouble with the follow code /** @Route(/{collection}/{id}, name=object, defaults={_format = json}) */
I have trouble putting together a delete statement in my Android application (I am
I have trouble connecting microstrategy to hive. I have followed every instruction here I
I have trouble with a query, the problem is that i am left joining
I have trouble printing simple text from a <h1> element: require 'nokogiri' doc =
I have trouble deserializing the result from my WCF webservice. The method returns a
I have trouble working with xml query. Below is the xml document. All I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.