Nice @Unwrap puzzel
lvdberg Oct 21, 2009 9:47 AMHi guys,
Yesterday I found a solution
(well sort of) for something which still keeps me puzzling. I have made repositories for a numebr of entities to speed-up access. Basicall they are Application scoped beans with a method with the @Unwrap te get a list of entities and a method with @Observer listening to changes. I am use them for all valueObjects (DataDictionaries) and and also to access List of real-time
entities which must be accessed by all users. When the Observerd method is called another event is created to warn all users (they have a page with a push in it which is triggered by the event. Everything works fine with the exception of one specific entity.
Some code:
@MappedSuperclass @Inheritance(strategy=InheritanceType.JOINED) public abstract class Organisation implements Serializable { ...} Entity @Table(name="MANAGEMENTCENTRES") public abstract class ManagementCentre extends Organisation { ..} @Entity @Table(name = "INC_EMERGENCY_CNTRS") public class EmergencyCentre extends ManagementCentre { ...} @Entity @Table(name = "TRAFFIC_MCS") public class TrafficManagementCentre extends ManagementCentre { ...} And the Repository Name("managementCentreRepository") @Scope(ScopeType.APPLICATION) @Startup @AutoCreate public class ManagementCentreRepository implements Serializable { private static final long serialVersionUID = 6455717316209216130L; // Framework context variables @Logger Log log; @In EntityManager entityManager; @In Map<String,String> messages; @In Events events; // Application context variables private final static String queryString = "select o " + "from ManagementCentre o " + " order by o.uniqueOrganisationID desc "; private List<ManagementCentre> centres; @Unwrap public synchronized List<ManagementCentre> getCentres(){ return centres; } /** This method is called at startup and whenever an important change has occured in the list of * management centres * */ @Observer(value="es.esam.im4u.centreEvent") @SuppressWarnings("unchecked") @Transactional public synchronized void readCentres(){ centres = entityManager.createQuery(queryString).getResultList(); log.info("Caching " + centres.size() + " ManagementCentres "); events.raiseAsynchronousEvent("es.esam.im4u.managementCentreRepository.refreshed"); } }
All the other Repositories work fine, but this specific one returns an error when I access it in the view. The relevant code in the view (I want to connect it to a new User:
<s:decorate id="centreField" template="../layout/edit.xhtml"> <ui:define name="label">#{messages['operator_managementCentre']}</ui:define> <h:selectOneMenu immediate="true" value="#{newOperatorAction.mc}"> <s:selectItems noSelectionLabel="select" value="#{managementCentreRepository}" var="c" label="#{c.name}" /> <a4j:support event="onchange" eventsQueue="inputQueue" reRender="centreField" ajaxSingle="true" /> <s:convertEntity /> </h:selectOneMenu> </s:decorate>
After two days of crunching I replaced the repository with a normal
query and everything works fine, but I am missing this specific part of the functionality
My main question is if anybody has experienced something like this or is there something really wrong with my perception of @Unwrap?
Thanks in advance,
Leo van den Berg