ClassCastException: ... cannot be cast to com.bah.englink.ej
chris.simons Dec 27, 2008 6:50 PM
Adam, et. Al,
I'd really appreciate your help here.
I'm following the Seam-Envers demo source code to implement a similar approach to my project. At this point, I'm just trying to pull a list of revisions to a particular object. Perhaps I'm not understanding what exactly is returned from using versionsReader.createQuery()?
I'm receiving ClassCastExceptions when pulling a list of Versions, but I'm not really understanding why.
What I have done:
- custom RevisionEntity and RevisionEntityListener
- Versioned, for testing, just a single field on the UserProfile entity
- attempting to pull a list of revisions for a specific object, in this case, UserProfile
- validated that Envers is working, revisions are being stored properly for UserProfile
- not working: pulling a list of revisions to UserProfile with key: -2
My VersionEntity (my RevisionEntity) stores userId, timestamp, and fullName.
In a working SFSB, I have a "getHistory()" method that I want to return a list of revisions (just the fields above, userId, timestamp, and fullName). When this list is empty, the page works. As soon as I make a revision and pull back a list of revisions, I get the ClassCastException. But why is Envers trying to pull the Version back as a UserProfile? Here is the getHistory() code:
@Factory("history") public List<Version> getHistory() { if (history == null) { List versions = versionsReader.createQuery().forRevisionsOfEntity(UserProfile.class, false, false) .add(VersionsRestrictions.idEq(cvUser.getUserProfile().getId())) .addOrder(RevisionProperty.desc()) .getResultList(); for (Object versionDataObject : versions) { Object[] versionData = (Object[]) versionDataObject; history.add(new Version((VersionEntity)versionData[0])); } } return history; }
In addition, because I'm following the Seam-Envers demo source code, I have a Version.java, though I don't really understand why it is needed since I already have a VersionEntity. Here is Version.java:
package com.bah.englink.ejb.revision;
public class Version { private VersionEntity version; public Version(VersionEntity version) { this.version = version; } public VersionEntity getVersion() { return version; } }
Lastly, a snippet from my JSF page wherein I place a RF dataTable of revisions:
<rich:dataTable id="revisions" var="version" value="#{userProfileManager.history}" border="1" rendered="true" rowClasses="oddRows, evenRows" sortMode="single"> <rich:column> <f:facet name="header"> <h:outputText value="Revision Type" /> </f:facet> <h:outputText value="#{version.version.userId}"/>
Again, I'm not sure I follow why I must have "version.version.userId".
I'd really appreciate your help. I feel like I'm quite close to having Envers implemented in the way that I want - but I'm not quite there.
Thanks.