Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate expecting wrong parameter type in HQL
    primarykey
    data
    text
    <p>We have an hierarchy of entities, e.g. abstract Basket and two concrete, which in turn can contain a list of some other items, for example, with exact same hierarchy(SaleBasketItem, ReturnBasketItem). </p> <pre><code>@Entity @XStreamAlias("basket") @DiscriminatorColumn(name = "basket_type") @DiscriminatorOptions(force = true) @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public abstract class Basket&lt;T extends BasketItem&gt; @Entity @DiscriminatorValue(value = "SALE") public class SaleBasket extends Basket&lt;SaleBasketItem&gt; @Entity @DiscriminatorValue(value = "RETURN") public class ReturnBasket extends Basket&lt;ReturnBasketItem&gt; @Entity @Table(name = "basket_item") @XStreamAlias("basket_str") @DiscriminatorColumn(name = "basket_item_type") @DiscriminatorOptions(force = true) @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public abstract class BasketItem&lt;U extends BasketItem, V extends Basket&gt; @Entity @DiscriminatorValue(value = "RETURN") public class ReturnBasketItem extends BasketItem&lt;ReturnBasketItem, ReturnBasket&gt; @Entity @DiscriminatorValue(value = "SALE") public class SaleBasketItem extends BasketItem&lt;SaleBasketItem, SaleBasket&gt; </code></pre> <p>So, the problem arises when I try to execute hql query like</p> <pre><code>"SELECT bi FROM " + basketType + "BasketItem bi JOIN bi.basket b JOIN b.saleSession JOIN bi.ware w WHERE b.state = :state" </code></pre> <p>where <code>basketType</code> is dynamically either "Sale" or "Return". Then I put that query in <code>TypedQuery</code> with type of <code>BasketItem</code> I need and try to <code>setParameter("state", state)</code>, where <code>state</code> is some enum representing state of concrete basket (different in each concrete class, not present in abstract class at all), which throws</p> <blockquote> <p>IllegalArgumentException(java.lang.IllegalArgumentException: Parameter value ... was not matching type)</p> </blockquote> <p>where type is <code>ReturnBasketState</code> when actual is <code>SaleBasket</code> state, or vice versa.</p> <p>So the question is - how to force Hibernate to expect correct type for that parameter?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload