Liferay多对多关系引发类强制异常 [英] Liferay Many-to-Many RelationShip Throws Class Cast Exception

查看:164
本文介绍了Liferay多对多关系引发类强制异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个演示liferay中关系的示例。我正在以书籍实体和作者为例进行多对多的关系。我在下面的博客中创建了这个例子。

I am creating one example which demonstrates relationship in liferay.I am taking example of Book entity and Author for many to many relationship.I am following below blog for creating this example.

http://www.liferaysavvy .com / 2014/01 / liferay-service-builder-many-to-many_12.html

但我遇到了类强制转换异常的问题。博客也写过,它正在抛出类强制转换异常。

But I faced the issue of class cast exception.In blog also it has been written that it is throwing class cast exception.

11:05:00,422 ERROR [RuntimePageImpl-2][render_portlet_jsp:132] null
java.lang.ClassCastException: com.ds.portlet.library.model.impl.AuthorImpl cannot be cast to com.ds.portlet.library.model.Author
        at com.ds.portlet.library.service.persistence.AuthorPersistenceImpl.fetchByPrimaryKey(AuthorPersistenceImpl.java:691)
        at com.ds.portlet.library.service.persistence.AuthorPersistenceImpl.findByPrimaryKey(AuthorPersistenceImpl.java:653)
        at com.ds.portlet.library.service.persistence.AuthorPersistenceImpl.findByPrimaryKey(AuthorPersistenceImpl.java:59)
        at com.liferay.portal.dao.shard.advice.ShardPersistenceAdvice.invoke(ShardPersistenceAdvice.java:54)
        at com.liferay.portal.service.persistence.impl.TableMapperImpl.getBaseModels(TableMapperImpl.java:400)
        at com.liferay.portal.service.persistence.impl.TableMapperImpl.getRightBaseModels(TableMapperImpl.java:265)
        at com.ds.portlet.library.service.persistence.BookPersistenceImpl.getAuthors(BookPersistenceImpl.java:1183)
        at com.ds.portlet.library.service.persistence.BookPersistenceImpl.getAuthors(BookPersistenceImpl.java:1162)
        at com.ds.portlet.library.service.persistence.BookPersistenceImpl.getAuthors(BookPersistenceImpl.java:1143)
        at com.liferay.portal.dao.shard.advice.ShardPersistenceAdvice.invoke(ShardPersistenceAdvice.java:54)
        at com.ds.portlet.library.service.base.AuthorLocalServiceBaseImpl.getBookAuthors(AuthorLocalServiceBaseImpl.java:374)
        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
        at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
        at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
        at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
        at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:175)
        at com.ds.portlet.library.service.AuthorLocalServiceUtil.getBookAuthors(AuthorLocalServiceUtil.java:321)
        at org.apache.jsp.view_jsp._jspService(view_jsp.java:420)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

我想知道背后的原因。

推荐答案

我希望所涉及的课程在课程路径上两次 - 类似于David Nebinger的回答在这篇文章中。他提到的原因是:您可能在全局类路径以及 WEB-INF / lib中有 xxx-service.jar ,或者您可以在 WEB-INF / lib 上添加它,并添加 WEB-INF / service 作为源文件夹,以便相同的类再次位于 WEB-INF / classes 中。

I'd expect the involved classes to be twice on the classpath - similar to what David Nebinger answered in this post. Reasons are what he mentions: You might have your xxx-service.jar on the global classpath as well as in your WEB-INF/lib, or you might have it on WEB-INF/lib and added WEB-INF/service as source folder, so that the same classes are in WEB-INF/classes again.

每当我看到类加载器无法将类转换为其合法的超类或接口时出现类加载器问题,这就是类路径上重复类的问题。在古代,这还包括一个荒谬的消息,即java对象不是java.lang.Object的后代 - 显然是错误的,但它意味着其他 java.lang.Object classpath。

Whenever I've seen classloader issues that a class cannot be typecasted to its legitimate superclass or interface, this was an issue of duplicate classes on the classpath. In the ancient past, this also included the ridiculous message that a java object is not a decendant of java.lang.Object - clearly wrong, but it meant the other java.lang.Object that was on the classpath.

棘手的是,他们需要一些特定的实例化顺序,并不总是很容易重现。如果您发现了一个总是收到消息的情况,它可能总是以同样的方式失败。 Liferay服务构建者中的多对多关系可能是触发这些问题的一种方式。

The tricky thing is that they need some specific order of instantiation that is not always easy to willingly reproduce. If you found a situation in which you'll always get the message, it will probably always fail the same way. Many-to-many-relationships in Liferay's service-builder might be a way to trigger these problems.

这篇关于Liferay多对多关系引发类强制异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆