-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: ClassCastException sort
PostPosted: Mon May 08, 2006 2:52 pm 
Newbie

Joined: Mon May 08, 2006 2:32 pm
Posts: 2
Location: Berlin
Im having an object that contains a list of replys. as long as the replys were not sorted anything went fine. but as soon as i added the sort attribute as shown bolow I got an ClassCastExcption when trying to load the object.

Mapping (extract)
<set
name="historyReplies"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
>
<key>
<column name="NOTIF_ID" />
</key>
<one-to-many
class="de.gedas.fraport.sms.server.model.HistoryReply"
/>
</set>

(I'm working with middle out and regenerated the Pojos, which relly changed fronm set to sortedset)
I've red in many forums that unfortunatelly all said the same thing:
I get a ClassCastException when I specify a collection sort attribute.

When you first instantiate a sorted collection, it must be an instance of SortedSet, or SortedMap. Use a TreeSet or TreeMap, for example.

this does not help at all because: I do not instantiate the set this does hibernate (at least hibernate tries to) as you can see in my DAO)-method:

public NotifEvent findById(java.lang.Long id) throws SmsBusinessException
{

Session session = HibernateUtil.currentSession();

try
{
NotifEvent instance = (NotifEvent) session.get(
"de.gedas.fraport.sms.server.model.NotifEvent", id);
if(LOGGER.isDebugEnabled())
{
if (instance == null)
{
LOGGER.debug("get successful, no instance found");
} else
{
LOGGER.debug("get successful, instance found");
}
}
return instance;
} catch (RuntimeException e)
{
if (LOGGER.isEnabledFor(Priority.ERROR))
{
LOGGER.error("NotifEventDAO.findById(...) failed " +
"for id: " + id);
LOGGER.error(e.getMessage(), e);
}
throw new SmsBusinessException("notif.event.load.failed.internal");
} finally
{
HibernateUtil.closeSession();
}
}


DOES ANYBODY HAVE ANY WHAT I HAVE TO DO TIO GET A SORTED COLLECTION???
Thanx in adavanced
Micha


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 2:57 pm 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
What value have you specified for the sort attribute? Is it 'natural' or an instance of java.util.Comparator? Also, post the exception stacktrace that you are seeing.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 5:22 am 
Newbie

Joined: Mon May 08, 2006 2:32 pm
Posts: 2
Location: Berlin
Hi,
as far asI understood the hibernate documentation:
sort="unsorted|natural|comparatorClass"
means I can either enter natural or unsorted or an comperator class. Thus natural is no compeartor class as unsorted is no comperator class.<BR>
The Stach trace is:
java.lang.ClassCastException: de.gedas.fraport.sms.server.model.HistoryEditor
at java.util.TreeMap.compare(TreeMap.java:1093)
at java.util.TreeMap.put(TreeMap.java:465)
at java.util.TreeSet.add(TreeSet.java:210)
at java.util.AbstractCollection.addAll(AbstractCollection.java:318)
at java.util.TreeSet.addAll(TreeSet.java:258)
at org.hibernate.collection.PersistentSet.endRead(PersistentSet.java:242)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:183)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:268)
at org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:249)
at org.hibernate.loader.Loader.endCollectionLoad(Loader.java:547)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:534)
at org.hibernate.loader.Loader.doQuery(Loader.java:429)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:211)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1427)
at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:111)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1426)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:274)
at org.hibernate.engine.PersistenceContext.initializeNonLazyCollections(PersistenceContext.java:796)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:216)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1338)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:116)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:101)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:167)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:621)
at de.gedas.fraport.sms.server.dao.NotifEventDAO.findById(NotifEventDAO.java:122)
at de.gedas.fraport.sms.server.notification.NotifManager.loadNotifPojoWrapper(NotifManager.java:278)
at de.gedas.fraport.sms.server.SmsServer.loadNotif(SmsServer.java:128)
at de.gedas.fraport.sms.web.action.NotifEventShowAction.execute(NotifEventShowAction.java:109)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.