« Return to Thread: Calculating progress for an entity based on data from another table

Calculating progress for an entity based on data from another table

by philk :: Rate this Message:

Reply to Author | View in Thread

Hello,

I am working with a legacy database where the warehouse order progress is  
calculated depending on many line items are finished. So I have 2 Entities:

WarehouseOrder
LineItem

the orders progress is calculated using the number of LineItems that have  
their state field set to anything but 1.

I would have a transient field in WarehouseOrder that holds the progress.  
I checked the @PostLoad listeners, but they have no session context so I  
can not execute any query. In Hibernate there is the @Formula annotation  
that allows you to specify a query for filling in the annotated field.

I tried this:

@SqlResultSetMapping(name = "progress", columns = @ColumnResult(name =  
"progress"))
@NamedNativeQuery(name = "progress", query = "select 100 * (select  
count(p) from LegacyOrderPosition p, LegacyPickOrder o where p.id=o.id and  
p.status!=1) / count(p) as progress", resultSetMapping = "scalar")

But to no avail. Of course I got it wrong somehow, I know :)


Any ideas how this could be solved in EL? Maybe using an embedded Entity?

Thanks for any input,
Phil
 
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

 « Return to Thread: Calculating progress for an entity based on data from another table