Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Calculating progress for an entity based on data from another table

You can define a relationship in EclipseLink based on any EclipseLink
Expression.  There is currently no JPA annotations for this, but you can use
a DescriptorCustomizer to add the mapping using the mapping API and setting
a selectionCriteria on the mapping.

Other options within JPA would be to query for the results instead of
mapping them.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Filtering.2C_Complex_Joins


philk wrote:
> 
> 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
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Calculating-progress-for-an-entity-based-on-data-from-another-table-tp24178554p24274638.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top