I ended up having to do something like this:

public abstract class HibernateConfirmationRepository<T extends
Confirmation>
                extends HibernateGenericRepository<T, Long> implements
                ConfirmationRepository<T> {

        public HibernateConfirmationRepository(Class<T> clazz) {
                super(clazz);
        }

        @SuppressWarnings("unchecked")
        public T findCurrentConfirmation(TaxEntity taxEntity) {
                Object[] params = { taxEntity, ActiveStatus.ACTIVE };
                List<T> confirmation = this.hibernateTemplate
                                .find(
                                                "from "
                                                                + 
this.getconfirmationObjectName()
                                                                + " where "
                                                                + "taxEntity=? 
and activeStatus=? order by
confirmationStamp.confirmDate desc",
                                                params);

                if (confirmation == null || confirmation.isEmpty()) {
                        return null;
                }

                return confirmation.get(0);

        }

        /**
         * To be implemented by domain-specific ConfirmationDetailRepositories 
in
         * order to retrieve the appropriate subclass.
         * 
         * @return Confirmation object name. Ex:
         *         "ServiceProviderElectionConfirmation"
         */
        protected abstract String getconfirmationObjectName();
}


Where subclasses would define the "ConfirmationObjectName" to be used in the
HSQL.

Martin Homik wrote:
> 
> Another related question is how to state Hibernate queries depending on
> Generics. For instance, you would like to state a generic query in
> ConfirmDetailsDaoHibernate:
> 
>  public List<T> findAllOrderByAlpha() {
>       return getHibernateTemplate().find(
>                       "from ConfirmDetails c order by c.name");
>  }
> 
> Well, this HQL is wrong, because it will return all ConfirmDetails and not
> only those of some sub type of ConfirmDetails. That is, this query commits
> to ConfirmDetails and is not generic. So, how to write generic queries in
> a formlike:
> 
>                       "from T c order by c.name", T);
> 
> with T the type of the class. T could be ConfirmDetails or
> ServiceProviderConfirmDetails.
> 
> Any idea?
> 
> 

-- 
View this message in context: 
http://www.nabble.com/GenericDao-and-Class-Hierarchy---Approach--tp14672300s2369p19256535.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to