users@jpa-spec.java.net

[jpa-spec users] Proposal: Introduce _at_Query annotation for fields

From: Daniel Sachse <sachsedaniel_at_googlemail.com>
Date: Thu, 8 Dec 2011 11:06:09 +0100

Hello everyone,

I would like to propose a new feature for JPA. To make it more clear,
I will show you my use case:

I have got a customer object with a list of offers:

<code>

@OneToMany
private List<Order> orders;

</code>

So far, so good. As soon as I want a List with all undelivered orders,
I have to create a separate business method, call the EntityManager
with a specific query and set the resultset in my POJO.
From my point of view, this is overhead!
My proposal:

<code>

@Transient
@Query("FROM Order WHERE delivered = false")
private List<Order> undeliveredOrders;

</code>

But I don't want it only to apply for collections, but also for other
field types:

<code>

@Transient
@Query("FROM Order WHERE status = ? ORDER BY ", OrderStatus.Failed)
private Order lastFailedOrder;

</code>

Additionally a FetchType would be good to specify.

Regards,

Daniel