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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:09:33+00:00 2026-05-13T19:09:33+00:00

I’ve been trying to use polymorphic query with JPA (hibernate as provider) in the

  • 0

I’ve been trying to use polymorphic query with JPA (hibernate as provider) in the following domain scenario:

PriceTable (1) <—>(n) ItemPrice (n) <—-> (1) Item

So for each PriceTable registered in my system I have a set of item prices which describe the price of a given item on that table. An item can be an Equipment or a Structure and I intend to increase the hierarchy.

The class declarations are as follows (plz assume that the ids are working):

@Entity
class PriceTable {
 private Set<ItemPrice> priceList = new HashSet<ItemPrice>();
 //getters & setters;
}


@Entity
class ItemPrice {
 private Item item;

    @Any(metaColumn = @Column(name = "itemtype"), fetch = FetchType.LAZY)
     @AnyMetaDef(idType = "long", 
            metaType = "string", 
            metaValues = {
             @MetaValue(value = "Equipment", targetEntity = Equipment.class),
             @MetaValue(value = "Structure", targetEntity = Structure.class)
            })
    @JoinColumn(name="itemid")
    public Item getItem(){ 
      return item; 
    }
}

@MappedSuperClass
class Item {
  //...
}

@Entity
class Equipment extends Item {
  //...
}

@Entity
class Structure extends Item {
  //...
}

When I attempt to query all the PriceTables that contain a given Item in its priceList using Query.setParameter for the kind of Item I’m interested in, it allways binds the parameter as null. Take a look at the query code:

String query = "from PriceTable pt "+ 
               "    where ? in " +
               "    (select ptpricelist.item.id from pt.priceList ptpricelist " +
               "       where ptpricelist.item.class = ?) ";

Query q = entityManager.createQuery(query);
q.setParameter(1, myItem.getId());
q.setParameter(2, "'Equipment'");

The trace hibernate gives me this:

2010-02-22 17:55:32,683 DEBUG [org.hibernate.type.NullableType:126] - binding null to parameter: 2

And of course doesn’t give me any value at all. The strange thing is if I set manually the matevalued parameter, like:

String query = "from PriceTable pt "+ 
               "    where ? in " +
               "    (select ptpricelist.item.id from pt.priceList ptpricelist " +
               "       where ptpricelist.item.class = 'Equipment') ";

Query q = entityManager.createQuery(query);
q.setParameter(1, myItem.getId());

It works perfectly. So I think hibernate/JPA doesn’t resolve the query parameter as a metavalue as it should (take a look at the hibernate documentation about this). Probably it was resolved as a string. Do you guys have any workaround this? I really don’t want to use switchs on my code just to overcome this setParameter strange behaviour.

thanks a lot!

  • 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-13T19:09:34+00:00Added an answer on May 13, 2026 at 7:09 pm

    Try dropping the single quotes from the literal:

    q.setParameter(2, "Equipment");
    

    instead of

    q.setParameter(2, "'Equipment'"); 
    

    If that doesn’t work, try using the fully-qualified class name.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post

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.