[hibernate-users] different HQL condition in classes with inheritance for different subclasses

Thomas Menke thomasml at cipher-code.de
Mon Jul 5 17:28:40 EDT 2010


Hi,

I am writing an application to manage a library. I am doing this for 
learning purposes only.

I have different customer types that have an associated maximum number 
of items that they may lend from the library.
The customers have a base class that looks like that (shortend for 
simplicity)

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name 
= "type")
abstract class Customer
{
   ...
   public abstract int getItemsAllowed();
   public Collection<ItemLoan> getItemLoans();
}

Then there may be subclasses like

@...
class NormalCustomer
{
   public static final int MAX_ITEMS = 5;
   public int getItemsAllowed() {return MAX_ITEMS;}
}

@...
class VIPCustomer
{
   public static final int MAX_ITEMS = 30;
   public int getItemsAllowed() {return MAX_ITEMS;}
}

Now I want to get a list with all customers that are currently lending 
the maximum allowed number of items (getItemLoans().size() == 
getItemsAllowed()).

Is something like that possible with one hql query?

Thanks,

Thomas


More information about the hibernate-users mailing list