voyent
Multiple entities in SELECT - how to show them in DataTable?  XML
Forum Index -> General Help
Author Message
kwedeer

Joined: 01/Jan/2009 00:00:00
Messages: 5
Offline


As I understand, it is the best option to wrap any result from JPQL (Java Persistence Query Language or EJBQL) into DataModel and the put the reference to this DataModel on the ice:DataTable. It is pretty easy to see how to do this, if the SELECT clause contains single entity - like in the code from BEA JPQL API reference:
Code:
EntityManager em = ...
 Query q = em.createQuery ("SELECT x FROM Magazine x");
 List<Magazine> results = (List<Magazine>) q.getResultList ();


One can simple call myDataModelInstance.setWrappedData(results) and that is all. But how to handle the case:
1) when there are multiple entities in the SELECT clause - like SELECT x, y from Magazine x, Article y, ...
2) when there are separate fields in the SELECT clause - like SELECT x.PublishinHouse, y.Author from Magazine x, Article y,...

Well - I see that one solution is to create separate Java class for each such query and this class can hold the record, resulting from such query. Well - there can be class MyRecord with properties x and y or even - MyRecord properties set can be the union of properties sets of x and y.

But it is not really nice solution how to handle this, because - queries with joins should be pretty common case for any well designed and denormalized data model and it ias a bit hard to image that I should create helper classes for any report I should make. Is there better solution to that?

I have tried to write (magazinePublishingHouse is property for Magazine x entity and it is PublishingHouse entity itself with property description):
Code:
<ice:outputText id="outputText7" value="#{currentRow['magazinePublishingHouse.description']}"/>


but there is error:
Code:
javax.servlet.ServletException: java.lang.Exception: javax.faces.FacesException: javax.el.ELException: javax.faces.el.PropertyNotFoundException: javax.el.PropertyNotFoundException: The class 'default.Magazine' does not have the property'magazinePublishingHouse.description'.

Is there any better solution than to write helper classes for each select?

I am useing NB, I can imagine that IDE can be of help to generate those helper classes - but then - the synchronization can emerge as issue: e.g. if one adds some new property in DB and entity, then he or she should add the same property for helper classes as well, etc.
mkat

Joined: 16/Oct/2008 00:00:00
Messages: 96
Offline


Hi.

If I'm understanding correctly that currentRow has a property magazinePublishingHouse and magazinePublishingHouse has a property description,

instead of

Code:
currentRow['magazinePublishingHouse.description']


try

Code:
currentRow['magazinePublishingHouse'].description


or

Code:
currentRow.magazinePublishingHouse.description



kwedeer

Joined: 01/Jan/2009 00:00:00
Messages: 5
Offline


mkat, many thanks - code:
Code:
currentRow['magazinePublishingHouse'].description

worked for me.
No I am exploring - whether it works, if I try to update "description" field.
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team