Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Calculations of field values using other tables
Calculations of field values using other tables [message #390286] Tue, 14 July 2009 08:51 Go to next message
Philipp Kursawe is currently offline Philipp KursaweFriend
Messages: 135
Registered: July 2009
Senior Member
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 #390294 is a reply to message #390286] Thu, 16 July 2009 14:04 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You could change this to a query instead of a persistence attribute.

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.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: Calculations of field values using other tables [message #390298 is a reply to message #390294] Thu, 16 July 2009 14:30 Go to previous message
Philipp Kursawe is currently offline Philipp KursaweFriend
Messages: 135
Registered: July 2009
Senior Member
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
Previous Topic:Unstable database connection causes EL to deadlock
Next Topic:Create additional views on session start
Goto Forum:
  


Current Time: Tue Apr 16 10:59:15 GMT 2024

Powered by FUDForum. Page generated in 0.49194 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top