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 8136243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:42:09+00:00 2026-06-06T10:42:09+00:00

Okay, so I have several tables Vote Contest ContestSegment ContestRegistration Submittable User The relationship

  • 0

Okay, so I have several tables

  • Vote
  • Contest
  • ContestSegment
  • ContestRegistration
  • Submittable
  • User

The relationship is that a Submittable may be submitted to a contest via creating a ContestRegistration, which is tied to a ContestSegment, which is tied to a Contest.

A Vote has a User and a reference to a ContestRegistration that the Vote relates to.

Pretty simple.

Now, the idea is that I want to hit a RESTful service which checks to see if I’ve already voted on one of the ContestRegistrations in a contest.

Everything is working except for the desired result.

The JPQL that I’m running looks like this:

SELECT DISTINCT v 
FROM Vote v, Contest c 
JOIN v.user vu 
LEFT JOIN c.segments cs 
LEFT JOIN cs.registrations csr 
LEFT JOIN csr.votes csrv 
WHERE vu.id = :userId 
AND cs.beginDate < CURRENT_TIMESTAMP 
AND cs.endDate > CURRENT_TIMESTAMP 
AND c.id = :contestId

The method looks like:

public Boolean hasUserVoted(User user, Contest contest){
    StringBuffer query = new StringBuffer()
    .append("SELECT DISTINCT v from Vote v, Contest c ")
    .append("JOIN v.user vu LEFT JOIN c.segments cs LEFT JOIN cs.registrations csr LEFT JOIN csr.votes csrv ")

    .append("WHERE vu.id = :userId ")
    .append("  ")
    .append("AND cs.beginDate < CURRENT_TIMESTAMP AND cs.endDate > CURRENT_TIMESTAMP AND c.id = :contestId ");
    Boolean hasVoted = true;
    try{
    Vote vote = (Vote)entityManager.createQuery(query.toString())
        .setParameter("userId", user.getId())
        .setParameter("contestId", contest.getId()).getSingleResult();
    }catch(NoResultException nre){
        hasVoted = false;
    }

    return hasVoted;
}

But when I return, no matter what I plug in, I’m always getting a true back (meaning I’ve already voted). For instance, I’ve voted on contest#1, but I haven’t voted on contest#2. If I plug in the value for contest#2, then I still get a true back. I’m fairly new to JPQL, so any help you can provide would be awesome! Thanks!

  • 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-06-06T10:42:10+00:00Added an answer on June 6, 2026 at 10:42 am

    With the use of left joins in your JPQL, it will return true unless the contest don’t exists. Its sounds like the csr.votes should be a normal join.

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

Sidebar

Related Questions

Okay here's the situation. Net 4 WPF NO Silverlight. I have several Views that
Okay I have a large CRUD app that uses tabs with Forms embedded in
I have several UIAlertViews that i want to display in a sequential order, and
Is it good or okay to have several frameworks in a project, or is
Okay so here is the problem I am having. I have several unit tests
I am writing some PHP. I have several classes that do not declare any
In my application I have several EditText. When the User clicks on the first,
Okay, I've realized that I really have asked way too many questions without contributing
I have an app that loads several resources when it's first run, which are
I have a table that displays a column of test names, with several (unlimited

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.