-->
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.  [ 8 posts ] 
Author Message
 Post subject: ClassCastException with proxies?
PostPosted: Thu Aug 12, 2010 2:02 pm 
Newbie

Joined: Thu Aug 12, 2010 1:29 pm
Posts: 4
Hello,

I'm running into an issue with hibernate search where i'm seeing a ClassCastException being thrown while ReflectionHelper.getMemberValue is being invoked. Digger further into the code revealed that hibernate was complaining it couldn't cast the proxied object that was passed into ReflectionHelper.getMemberValue to it's concrete type. Does anyone know why this would be happening?


Top
 Profile  
 
 Post subject: Re: ClassCastException with proxies?
PostPosted: Fri Aug 13, 2010 7:56 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Could you post your annotated classes and the session code which triggers the exception. Also which version of Hibernate Core and Search are you using?


Top
 Profile  
 
 Post subject: Re: ClassCastException with proxies?
PostPosted: Fri Aug 13, 2010 9:36 am 
Newbie

Joined: Thu Aug 12, 2010 1:29 pm
Posts: 4
Sure, we are using Hibernate 3.5.2 and search 3.2.0, although i saw this issue happening with search 3.1.0, however the exception in 3.1.0 was being swallowed so we didn't see anything until we started using 3.2.0

Here are the classes, i omitted some code in the classes i didn't think was relevant for brevity.

Code:
@Entity
@Indexed
@Table(name = "scorecardnodes")
@Proxy(proxyClass = com.spider.cms.hdao.IScorecardNode.class)
public class ScorecardNodeHDao extends BaseNodeHDao<IScorecardNode> implements IScorecardNode {

   private IScorecardNode rootNode;
   private Set<IScorecardNodeNote> notes;

...

   @OneToMany(targetEntity = ScorecardNodeNoteHDao.class, mappedBy = "scorecardNode")
   @IndexedEmbedded(targetElement = ScorecardNodeNoteHDao.class)
   public Set<IScorecardNodeNote> getNotes() {
      return notes;
   }
   public void setNotes(Set<IScorecardNodeNote> notes) {
      this.notes = notes;
   }
   
   @ManyToOne(targetEntity = ScorecardNodeHDao.class, fetch = FetchType.LAZY)
   @JoinColumn(name = "scorecardrootnodeid")
   public IScorecardNode getRootNode() {
      return rootNode;
   }
   public void setRootNode(IScorecardNode root) {
      this.rootNode = root;
   }

...

}


Code:
@Entity
@Table(name = "notes")
@Proxy(proxyClass = com.spider.cms.hdao.IScorecardNodeNote.class)
public class ScorecardNodeNoteHDao extends BaseDomainObjectWithIdHDao implements IScorecardNodeNote {

   private IScorecardNode scorecardNode;
   private IScorecardNodeNote rootNote;
   private List<IScorecardNodeNote> replies = new ArrayList<IScorecardNodeNote>();
...

   @ManyToOne(targetEntity = com.spider.cms.hdao.impl.ScorecardNodeHDao.class, fetch = FetchType.LAZY)
   @JoinColumn(name = "scorecardnodeid")
   @ContainedIn
   public IScorecardNode getScorecardNode() {
      // includes this so the scorecard node ID is definitely populated
      if (scorecardNode == null && getRootNote() != null) {
         return getRootNote().getScorecardNode();
      }
      return scorecardNode;
   }
   public void setScorecardNode(IScorecardNode scorecardNode) {
      this.scorecardNode = scorecardNode;
   }

   
   @ManyToOne(targetEntity = com.spider.cms.hdao.impl.ScorecardNodeNoteHDao.class, fetch = FetchType.LAZY)
   @JoinColumn(name = "rootnoteid")
   public IScorecardNodeNote getRootNote() {
      return rootNote;
   }
   public void setRootNote(IScorecardNodeNote root) {
      this.rootNote = root;
   }

   @OneToMany(targetEntity = com.spider.cms.hdao.impl.ScorecardNodeNoteHDao.class, mappedBy = "rootNote", fetch = FetchType.LAZY)
   @OrderBy(clause = "creationdate ASC")
   @Cascade(CascadeType.DELETE)
   public List<IScorecardNodeNote> getReplies() {
      return replies;
   }
   
   public void setReplies(List<IScorecardNodeNote> replies) {
      this.replies = replies;
   }
...

}


We've encountered the error while trying to delete an object from the database using the code below

Code:
   public void deleteScorecardNote(Integer noteId, String database) {
      IScorecardNodeNote note = getScorecardNodeNote(noteId, false, database);
      getHibernateTemplate(database).delete(note);
   }


I'm not sure if this helps but while tracing through the execution, the ClassCastException is happening when the id method is being invoked on a proxied instance of IScorecardNode. Thanks for your assistance.


Top
 Profile  
 
 Post subject: Re: ClassCastException with proxies?
PostPosted: Fri Aug 13, 2010 9:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Could you also post the full stacktrace of the exception?


Top
 Profile  
 
 Post subject: Re: ClassCastException with proxies?
PostPosted: Fri Aug 13, 2010 10:10 am 
Newbie

Joined: Thu Aug 12, 2010 1:29 pm
Posts: 4
ERROR 2010-08-13 09:50:52,794 (JsonAwareDispatcherServlet:triggerAfterCompletion) - HandlerInterceptor.afterCompletion threw exception
org.springframework.orm.hibernate3.HibernateSystemException: Error while indexing in Hibernate Search (before transaction completion); nested exception is org.hibernate.HibernateException: Error while indexing in Hibernate Search (before transaction completion)
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)
at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:793)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:664)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at com.spider.cms.framework.springx.CmsTransactionHandler.finishTransaction(CmsTransactionHandler.java:89)
at com.spider.cms.framework.springx.CmsTransactionHandler.afterCompletion(CmsTransactionHandler.java:82)
at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletion(DispatcherServlet.java:1121)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:811)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at com.spider.cms.framework.springx.JsonAwareDispatcherServlet.doService(JsonAwareDispatcherServlet.java:18)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.spider.cms.framework.gzipfilter.CompressionFilter.doFilter(CompressionFilter.java:145)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.spider.cms.framework.ContentTypeFilter.doFilterInternal(ContentTypeFilter.java:83)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at net.sf.morph.web.MorphFilter.doFilter(MorphFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.spider.cms.framework.BrowserCompatabilityFilter.doFilterInternal(BrowserCompatabilityFilter.java:32)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.spider.cms.framework.springx.AvailableResourceFilter.wrapRequestWithOpenSession(AvailableResourceFilter.java:142)
at com.spider.cms.framework.springx.AvailableResourceFilter.doFilterInternal(AvailableResourceFilter.java:72)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.spider.cms.framework.RequestLogFilter.doFilterInternal(RequestLogFilter.java:39)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.spider.cms.framework.SetUnicodeEncodingFilter.doFilter(SetUnicodeEncodingFilter.java:38)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.HibernateException: Error while indexing in Hibernate Search (before transaction completion)
at org.hibernate.search.backend.impl.EventSourceTransactionContext$DelegateToSynchronizationOnBeforeTx.doBeforeTransactionCompletion(EventSourceTransactionContext.java:147)
at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:530)
at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:211)
at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:563)
at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:229)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:142)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
... 50 more
Caused by: java.lang.IllegalStateException: Could not get property value
at org.hibernate.search.util.ReflectionHelper.getMemberValue(ReflectionHelper.java:67)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.addWorkForEmbeddedValue(DocumentBuilderContainedEntity.java:724)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.processSingleContainedInInstance(DocumentBuilderContainedEntity.java:709)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.processContainedInInstances(DocumentBuilderContainedEntity.java:664)
at org.hibernate.search.engine.DocumentBuilderContainedEntity.addWorkToQueue(DocumentBuilderContainedEntity.java:612)
at org.hibernate.search.backend.impl.BatchedQueueingProcessor.addWorkToBuilderQueue(BatchedQueueingProcessor.java:270)
at org.hibernate.search.backend.impl.BatchedQueueingProcessor.processWorkByLayer(BatchedQueueingProcessor.java:248)
at org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:148)
at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.beforeCompletion(PostTransactionWorkQueueSynchronization.java:70)
at org.hibernate.search.backend.impl.EventSourceTransactionContext$DelegateToSynchronizationOnBeforeTx.doBeforeTransactionCompletion(EventSourceTransactionContext.java:144)
... 56 more
Caused by: java.lang.IllegalArgumentException: Invoking id with wrong parameters
at org.hibernate.annotations.common.reflection.java.JavaXProperty.invoke(JavaXProperty.java:84)
at org.hibernate.search.util.ReflectionHelper.getMemberValue(ReflectionHelper.java:64)
... 65 more
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@117b3de2
at sun.reflect.GeneratedMethodAccessor178.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.annotations.common.reflection.java.JavaXProperty.invoke(JavaXProperty.java:74)
... 66 more


Top
 Profile  
 
 Post subject: Re: ClassCastException with proxies?
PostPosted: Mon Aug 16, 2010 7:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

there are still a lot of things behind the scenes which are not clear from the example. How do your interfaces look like, eg IScorecardNode and IScorecardNodeNote? What exactly does getScorecardNodeNote(noteId, false, database) do and how are the Sessions managed.
the best would be if you could create a testcase we could run. You can create a jira issue in HSEARCH for it and attach it to your testcase.

--Hardy


Top
 Profile  
 
 Post subject: Re: ClassCastException with proxies?
PostPosted: Tue Aug 17, 2010 11:11 pm 
Newbie

Joined: Thu Aug 12, 2010 1:29 pm
Posts: 4
I created a test case, i couldn't exactly replicate the error i saw earlier, but it is close. I posted the bug here

http://opensource.atlassian.com/project ... SEARCH-577


Top
 Profile  
 
 Post subject: Re: ClassCastException with proxies?
PostPosted: Thu Aug 19, 2010 2:45 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Thanks. I'll look into it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.