0

I am trying to implement many to many mapping with liferay service builder. I have found one blog on liferay savvy which explains how to implement it and provides a war file as well.

You can download from here.

It gets deployed successfully and also allows you to create student and courses along with their mapping.

After adding some dummy data when I try to fetch courses based on student id with

List<Course> studentCourseList = CourseLocalServiceUtil.getStudentCourses(xxxx)

where xxxx is student id captured from meera_students_courses table. and then iterating it over for loop

for(Course course : studentCourseList){
 ...
 }

I got java.lang.ClassCastException: com.meera.db.model.impl.CourseImpl cannot be cast to com.meera.db.model.Course exception.

I have checked the list size and it gives proper count. So iteration of the list where casting happens, gives above exception.

Any help on this is appreciated.

suyash
  • 1,254
  • 1
  • 15
  • 33
  • Please refer to [Liferay Many-to-Many RelationShip Throws Class Cast Exception](http://stackoverflow.com/questions/30437080/liferay-many-to-many-relationship-throws-class-cast-exception) – Olaf Kock Sep 02 '15 at 07:22
  • I have checked, there are no duplicate classes. The error occurs while iteration over the list. – suyash Sep 02 '15 at 07:39
  • Whenever you can't typecast to a legitimate interface, you *definitely* have the interface on the classpath twice. It's just the error message that doesn't distinguish between the different versions. The VM tries to typecast to *the other* Interface but only prints the name, not the available interface's classloader identity. Look again, look harder. I guarantee that you have (at least) the Course interface twice. Inspect the global classpath, the WEB-INF/classes folder and all jars in WEB-INF/lib. You will find them eventually – Olaf Kock Sep 02 '15 at 09:06

0 Answers0