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

  • Home
  • SEARCH
  • 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 6864595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:55:52+00:00 2026-05-27T02:55:52+00:00

I have classes: class User{ String id; ArrayList<UserAttribute> attributeList=new ArrayList<UserAttribute>(); } class UserAttribute{ User

  • 0

I have classes:

class User{
String id;
ArrayList<UserAttribute> attributeList=new ArrayList<UserAttribute>();
}

class UserAttribute{
User user;
String value;
String key;
}

I have tables associated to classes.

table user

column id

table user_attribute

column user_id
column key
column value

example user table content

user_id="123"

user_id="234"

example user_attribute table contents

user_id="123", key="address", value="green house street"

user_id=234, key="address", value="blue house street"

user_id="123", key="phone", value="234324"

user_id="234", key="phone", value="786988"

I want to get the user who has address “green house street” and(not or) has phone “234324”

I write sql(oracle) in sql editor:

 select u.* from user u left join user_attribute prop on u.id=prop.user_id inner join user_attribute prop2 on prop.user_id = prop2.user_id where prop.value = 'green house street' and prop.key = 'address' and prop2.key ='phone'  and prop2.value = '234324';

I tried many thing on hibernate side: but cannot use join because get

“unecpected token on”

error when using “on” clause.

in the end I wrote

entityManager.createQuery(
select u from User u, u.attributeList prop, u.attributeList prop2 where prop.value = :address and prop.key = :key and prop2.key =:key2  and prop2.value = :phone and prop.user.id=u.id and prop2.user.id=u.id and prop2.user.id=prop.user.id
)..setParameter("key", "address")
                .setParameter("phone", "234324")
                .setParameter("key2", "phone")
                .setParameter("address", "green house street").getSingleResult();

still no chance,

I try hard to find a single query solution but cannot achive so far.
Thanks for any idea.

  • 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-27T02:55:53+00:00Added an answer on May 27, 2026 at 2:55 am

    You need to make two joins, but don’t need to specify any on clause, since Hibernate knows, thanks to the mapping of the association, how the tables are linked together. So the following query should work:

    select u from User u
    inner join u.attributeList a1
    inner join u.attributeList a2
    where a1.value = 'green house street' and a1.key = 'address' 
    and a2.key ='phone' and a2.value = '234324'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes class Facebook { String fid String name User user static
I have two domain classes: User : class User { String login String password
I have the following domain classes: Holiday : class Holiday { String justification User
Two classes: <class name=SpreadsheetImportTemplate table=spreadsheetimport_template> <id name=id type=int column=id unsaved-value=0> <generator class=native /> </id>
I have two classes class A { public string something { get; set; }
Say i have the following two classes: public class User { public int ID
I have two following classes: public class User { public virtual Guid Id {
i have the following classes : class Address { String street; String street2; String
I have the following two classes: import java.io.*; import java.util.*; public class User {
Scenario 1: I have two classes: Post : class Post { String content Date

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.