Calculations of field values using other tables [message #390286] |
Tue, 14 July 2009 04:51  |
Eclipse User |
|
|
|
Hello,
is it possible to calculate a fields value using a SQL statement?
I have a progress and a status field that would have to be calculated by
values from another table.
OrderEntity {
float progress;
int shortageLines;
}
The shortageLines field would be calculated by the number of line items
from the line_items table that have been picked with a shortage. The
progress field is the overal % of already picked line items versus the
total number of line items to pick.
Any idea if something like that is possible to "inject" into the object
using JPA?
Thanks,
Phil
|
|
|
|
Re: Calculations of field values using other tables [message #390298 is a reply to message #390294] |
Thu, 16 July 2009 10:30  |
Eclipse User |
|
|
|
James wrote:
> You could change this to a query instead of a persistence attribute.
What you mean by that? How would I annotate that or create this query?
>
> If you need to map it, you could use a TransformationMapping in
> EclipseLink, or use a postBuild event to query the data. You could also
> just lazy initialize the field using a query.
>
> Another solution would be define a database view that include the
> computed values and map your object to the view.
I am doing that right now, it might be the most performant solution.
But anyway I am interested, in case the DB does not support views, how I
would use a TransformationMapping in my particular case. Do you have an
example of that for me?
Thanks,
Phil
|
|
|
Powered by
FUDForum. Page generated in 0.37514 seconds