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.  [ 4 posts ] 
Author Message
 Post subject: class cast exception in find method - unusual
PostPosted: Fri Apr 15, 2011 5:36 pm 
Newbie

Joined: Wed Mar 25, 2009 6:56 am
Posts: 2
Hi
We are getting the following exception, when we try to fetch data using Query.list. Some scenario we are getting on instance of PersistentSet , but expected is an implementation of List due to which, getting class cast exception.

Version of Hibernate 3.2. it would be great if some help to resolve this issue.

java.lang.ClassCastException: org.hibernate.collection.PersistentSet cannot be cast to java.util.List
at $Proxy102.getDatalist(Unknown Source)
at com.test.service.impl.MyPageServiceImpl.getMyPods(MyPageServiceImpl.java:185)
at com.test.service.impl.MyPageServiceImpl.getMyPagePodDetails(MyPageServiceImpl.java:79)
at sun.reflect.GeneratedMethodAccessor1122.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:77)
at com.test.management.CallTracer.trace(CallTracer.java:46)
at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:616)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:64)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:165)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)


Top
 Profile  
 
 Post subject: Re: class cast exception in find method - unusual
PostPosted: Sat Apr 16, 2011 2:26 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:30 pm
Posts: 46
Location: Fortaleza, Brazil
Are you using lazy="extra" on the entities returning PersistentSet , or have some type of ordered bag / List config? For the latter see:

http://docs.jboss.org/hibernate/core/3. ... nt-classes


Top
 Profile  
 
 Post subject: Re: class cast exception in find method - unusual
PostPosted: Mon Apr 18, 2011 3:08 pm 
Newbie

Joined: Wed Mar 25, 2009 6:56 am
Posts: 2
Here is the code snippet which can explain what we are doing..

Basically the DAO class returns an instance of List most of the cases. But in some cases it is returning an instance of a PersistentSet due to which we are getting a ClassCastException.
Since this is happening only in production and that too for a specific users we are not able to figure out the root cause as it cant be re-producible in our test environments.


Peristent Entity:
--------------------
public class MyEntityImpl implements MyEntity {

private Long id;
private User user;
private Integer displayOrder;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@ManyToOne(targetEntity = UserImpl.class, fetch = FetchType.LAZY)
@JoinColumn(name = "users_id", referencedColumnName = "id", nullable = false, updatable = false)
public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

@Column(name = "display_order")
public Integer getDisplayOrder() {
return displayOrder;
}

public void setDisplayOrder(Integer displayOrder) {
this.displayOrder = displayOrder;
}
}


DAO Class:
--------------
public class MyEntityDAO {
public List<MyEntity> getMyEntities(Long userId)
{
List<MyEntity> list = null;
String queryString = "from MyEntityImpl ms where ms.user.id = ? order by ms.displayOrder";

return (List) execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
Query queryObject = session.createQuery(queryString);
queryObject.setParameter(0, userId);
return queryObject.list();
}

}
}
}

TEST Class:
----------------
public class MyEntityTest {

public void testMyEntitiesDAO {

MyEntityDAO dao = new MyEntityDAO();

List myEntitties = dao.getMyEntities(new Long(9999));
}
}


Top
 Profile  
 
 Post subject: Re: class cast exception in find method - unusual
PostPosted: Tue Apr 19, 2011 4:25 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
Quote:
Version of Hibernate 3.2. it would be great if some help to resolve this issue.

that's likely a bug, and you're using a stone-aged version.. time to try an update?
All issues are tracked here

_________________
Sanne
http://in.relation.to/


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