Hi Thomas,

In case you haven't noticed, I opened
https://issues.apache.org/jira/browse/DELTASPIKE-699 and submitted a patch.
The patch covers a somewhat larger scope as the issue described here
affects any method creating QuerySelections. I haven't submitted a ICLA
yet, as I'm having some trouble with faxing at the moment, but will do that
soon.

Regards,
Radu


On Tue, Aug 26, 2014 at 12:45 PM, Thomas Hug <[email protected]> wrote:

> Hi Radu
> Yes good catch - makes perfectly sense. Do you mind creating a JIRA ticket
> for that?
>
>
> On Tue, Aug 26, 2014 at 12:15 PM, Radu Creanga <[email protected]> wrote:
>
> > Hi all,
> >
> > Suppose one has an entity class hierarchy, such as when moving auditing
> > fields into a mapped superclass.
> >
> > @MappedSuperclass
> > @EntityListeners(AuditEntityListener.class)
> > public abstract class Auditable implements Serializable {
> >
> >   @CreatedOn
> >   @Temporal(TemporalType.TIMESTAMP)
> >   private Date created;
> >
> >   @ModifiedOn
> >   @Temporal(TemporalType.TIMESTAMP)
> >   private Date modified;
> >
> >   // getters, setters
> >
> > }
> >
> > @Entity
> > public class Item extends Auditable {
> >
> >   @Id
> >   private Long id;
> >   @Basic
> >   private String name;
> >
> >   // getters, setters
> >
> > }
> >
> > Then an metamodel processor would generate the following metamodel
> classes:
> >
> > @StaticMetamodel(Auditable.class)
> > public abstract class Auditable_ {
> >
> > public static volatile SingularAttribute<Auditable, Date> created;
> >  public static volatile SingularAttribute<Auditable, Date> modified;
> >
> > }
> >
> > @StaticMetamodel(Item.class)
> > public abstract class Item_ extends
> > com.mobilabsolutions.nappkin.web.dto.Auditable_ {
> >
> > public static volatile SingularAttribute<Item, Long> id;
> >         public static volatile SingularAttribute<Item, String> name;
> >
> > }
> >
> > For the sake of completeness, here's the repository declaration with
> > criteria support:
> >
> > @Repository
> > public interface ItemRepository extends EntityRepository<Item, Long>,
> >     CriteriaSupport<Item> {
> >
> > }
> >
> > Then, if one wants to do the following:
> >
> > @Inject
> > private ItemRepository itemRepository;
> >
> > public void someMethod() {
> >   this.itemRepository.criteria().select(
> >         this.itemRepository.attribute(Item_.name),
> >         *this.itemRepository.attribute(Item_.modified)*);
> > }
> >
> > the source won't compile, because the declaration of the attribute()
> method
> > in CriteriaSupport:
> >
> > public interface CriteriaSupport<E>
> > {
> >     ...
> >
> >     /**
> >      * Create a query selection for an Entity attribute.
> >      * @param attribute Attribute to show up in the result selection
> >      * @return          {@link QuerySelection} part of a {@link
> > Criteria#select(Class, QuerySelection...)} call.
> >      */
> >     <X> QuerySelection<E, X> attribute(SingularAttribute<E, X>
> attribute);
> >
> >     ...
> >
> > }
> >
> > Wouldn't it make sense (and possible?) to change it to:
> >
> > <X> QuerySelection<E, X> attribute(SingularAttribute<? super E, X>
> > attribute);
> >
> > The mapped superclass doesn't have to have anything to do with auditing,
> > but that's the example that came to mind.
> >
> > Best regards,
> > Radu
> >
>

Reply via email to