留言板

[LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

thumbnail
Gianluca Pindinelli,修改在13 年前。

[LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 10-3-17 最近的帖子
Hi community,
I have a strange problem with my Struts Action portlet: the portlet has a servlet that export certain data into Excel format (by org.apache.poi.hssf.usermodel.HSSFWorkbook class) and use a LocalServiceUtil class for load a list of object (i.e. Bollettino object).
The problem is that when load the list (BollettinoLocalServiceUtil.getBollettinos(-1, -1)) the method getBollettinos generate the exception:


java.lang.ClassCastException: it...BollettinoImpl cannot be cast to it....Bollettino
....
....


The problem, by searching into forums and other resources, seems to be due to the existence of a duplicate library into classloader.

But this problem happens only when deploy portlet after restarting the server: if I use the servlet after firts start of JBoss(or after restart) the problem disappear and the XLS file is sucessfully created. emoticon.

how can I fix this? Why LF duplicate library (how library? portal-service?) after portlet deploy?

The server installation seems to be ok and I never manually changed the libraries or their arrangement inside the server.

In the past I have created other portlet with same functionality (LF 5.2.3/Tomcat) without any problem.

Thank's in advance.
Jens Göring,修改在13 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

New Member 帖子: 22 加入日期: 10-11-18 最近的帖子
Do you use overflowToDisk or clustering with EHCache? Both can lead to very strange ClassCastExceptions on JBoss with Liferay. See http://issues.liferay.com/browse/LPS-13398. It's hard to tell if this is the case here without complete stacktrace.

Jens Göring
thumbnail
Gianluca Pindinelli,修改在13 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 10-3-17 最近的帖子
Thank's for your response Jens.

Here the complete stacktrace:


java.lang.ClassCastException: it.linksmt.cdb.pagamenti.model.impl.BollettinoImpl cannot be cast to it.linksmt.cdb.pagamenti.model.Bollettino
        at it.linksmt.cdb.pagamenti.service.impl.BollettinoLocalServiceImpl.getBollettinos(BollettinoLocalServiceImpl.java:96)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        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:309)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
        at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionInterceptor.invoke(DynamicDataSourceTransactionInterceptor.java:44)
        at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
        at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
        at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:58)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy589.getBollettinos(Unknown Source)
        at it.linksmt.cdb.pagamenti.service.BollettinoLocalServiceUtil.getBollettinos(BollettinoLocalServiceUtil.java:188)
        at it.linksmt.cdb.pagamenti.servlet.ExportXlsServlet.doPost(ExportXlsServlet.java:72)
        at it.linksmt.cdb.pagamenti.servlet.ExportXlsServlet.doGet(ExportXlsServlet.java:93)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        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 org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        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:235)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
        at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:436)
        at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:384)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)


Note that this problem appear only into servlet..the same method (getBollettinos) called into an action works perfectly.

Do you use overflowToDisk or clustering with EHCache? Both can lead to very strange ClassCastExceptions on JBoss with Liferay. See http://issues.liferay.com/browse/LPS-13398.


No..the server is not clustered and the EHCache is setted to default values (I never changed the default values); however, all the parameters seem correct.

At this point I think that the problem is into JBoss configuration but I don't know what to change.

Any ideas?

Thanks again in advance.
Jens Göring,修改在13 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

New Member 帖子: 22 加入日期: 10-11-18 最近的帖子
Nope, sorry, that doesn't look related to the problem I had. :-(
thumbnail
Gianluca Pindinelli,修改在13 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 10-3-17 最近的帖子
Anyone knows a solution? emoticon
thumbnail
Minhchau Dang,修改在13 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Liferay Master 帖子: 598 加入日期: 07-10-22 最近的帖子
Gianluca Pindinelli:
But this problem happens only when deploy portlet after restarting the server: if I use the servlet after firts start of JBoss(or after restart) the problem disappear and the XLS file is sucessfully created. emoticon.

So, to understand you correctly, you are saying that (1) the exceptions happen in the servlet, but no exceptions happen in the portlet even when the portlet calls the same services, and (2) there is no exception on first deployment, but errors come up when you redeploy the portlet a second or third time.

In that case, JBoss is probably caching the class loader for the servlet class, but does not do so for the portlet class. I suspect that the only way to resolve it would be to manually undeploy your plugin by deleting the folder, wait for JBoss to unregister it, and then redeploy your plugin.

If even that doesn't work, you will need to either use a different application server for development, or you will need to go through the tedious process of undeploying your plugin and restarting your JBoss instance every time you make a change.
thumbnail
Gianluca Pindinelli,修改在13 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 10-3-17 最近的帖子
Hi Minhchau,
thanks for your reply!

So, to understand you correctly, you are saying that (1) the exceptions happen in the servlet, but no exceptions happen in the portlet even when the portlet calls the same services, and (2) there is no exception on first deployment, but errors come up when you redeploy the portlet a second or third time.


Yes..you have exactly described the problem. And I add that, at this point, the problem is certainly jboss because on Tomcat (in my previous projects) is all OK.

In that case, JBoss is probably caching the class loader for the servlet class, but does not do so for the portlet class. I suspect that the only way to resolve it would be to manually undeploy your plugin by deleting the folder, wait for JBoss to unregister it, and then redeploy your plugin.


Unfortunately this does not work...always same exception emoticon.

If even that doesn't work, you will need to either use a different application server for development, or you will need to go through the tedious process of undeploying your plugin and restarting your JBoss instance every time you make a change.


Unfortunately I can't use different AS and restart the server every time I deploy is a significant problem, because the system is on a production server.

Exists a way for disable the caching system of jboss AS for the servlet class or other possible solutions?

EDIT:
My portlet is a Struts Action portlet (org.apache.portals.bridges.struts.StrutsPortlet) and the problem seems to be like this:
http://www.liferay.com/community/forums/-/message_boards/message/4363758#_19_message_4363758... Jboss seems to have problem with classloader but I am not able to find how to solve the conflict..
I also noticed that the problem also appears with the filters (javax.portlet.filter.RenderFilter): I am forced to restart the server to see the changes made to the portlet filter...

Thanks in advance.
thumbnail
Gianluca Pindinelli,修改在13 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 10-3-17 最近的帖子
Hi all!

I have an interesting update: I'm trying to execute my portlet on Liferay 6 Tomcat bundled and...surprise! The exception is raised however!!!
Exactly the same problem (after server restart all OK, after deploy KO).

So, the problem is not specific of Jboss (and its classloader) but is a portlet problem!

Here paste the portlet.xml:

<portlet>
		<portlet-name>PortletBE</portlet-name>
		<display-name>Back End</display-name>
		<portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>
		<init-param>
			<name>ServletContextProvider</name>
			<value>com.liferay.util.bridges.struts.LiferayServletContextProviderWrapper</value>
		</init-param>
		<init-param>
			<name>check-auth-token</name>
			<value>false</value>
		</init-param>
		<init-param>
			<name>EditPage</name>
			<value>/portlet_action/edit</value>
		</init-param>
		<init-param>
			<name>HelpPage</name>
			<value>/portlet_action/help</value>
		</init-param>
		<init-param>
			<name>ViewPage</name>
			<value>/portlet_action/list</value>
		</init-param>
		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>edit</portlet-mode>
			<portlet-mode>help</portlet-mode>
		</supports>
		<portlet-info>
			<title>Back End</title>
			<short-title>Portlet BE</short-title>
			<keywords>Portlet BE</keywords>
		</portlet-info>
		<security-role-ref>
			<role-name>administrator</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>power-user</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>user</role-name>
		</security-role-ref>
	</portlet>


and the liferay-portlet.xml:

<portlet>
		<portlet-name>PortletBE</portlet-name>
		<portlet-url-class>com.liferay.portal.apache.bridges.struts.LiferayStrutsPortletURLImpl</portlet-url-class>
		<use-default-template>true</use-default-template>
		<header-portlet-css>/html/portlet/style/style.css</header-portlet-css>
		<header-portlet-javascript>/html/portlet/script/script.js</header-portlet-javascript>
		<header-portlet-javascript>/html/portlet/script/jquery-1.4.4.min.js</header-portlet-javascript>
	</portlet>


There are any problems with org.apache.portals.bridges.struts.StrutsPortlet portlet type and com.liferay.util.bridges.struts.LiferayServletContextProviderWrapper ServletContextProvider??? There are mistakes that I'm not seeing?

The portlet was created by the example on the SVN repository of Liferay (http://svn.liferay.com/repos/public/plugins/trunk/portlets/sample-struts-portlet).

Thanks for your attention.
thumbnail
Gianluca Pindinelli,修改在13 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 10-3-17 最近的帖子
Nobody has this problem? Nobody has ever used a servlet into a portlet that invokes a service (LocalServiceUtil) in it (with LF 6.0.5)? emoticon
thumbnail
Gianluca Pindinelli,修改在13 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 10-3-17 最近的帖子
Well community!
I am the classic "needle in a haystack"?emoticon
Valohk Blackwood,修改在12 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

New Member 帖子: 4 加入日期: 11-3-21 最近的帖子
Hi,
I have a similar problem with my portlet. Did you find any solution to this problem?
thumbnail
Gianluca Pindinelli,修改在12 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 10-3-17 最近的帖子
No sorry,
for now I found no solution to the problem. The only "way" is restarting the server when deploy updated portlets...emoticon
Terry AY,修改在12 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

New Member 帖子: 3 加入日期: 11-5-30 最近的帖子
Hi all,

I have a similar problem as Pindinelli described.
My config. is Tomcat + Liferay 6.0.6 + JSPPortlet + MYSQL.

I have 2 custom portlets. One has a servlet to retrieve data instantly from DB using Ajax and the other is a form submission flow to enquire data with certain criteria. Both are retrieving same set of tables and built from service.xml.

My scenario:
When I use one of portlet ( portlet A ), it works fine.
Then I use the other ( portlet B ), I will get this ClassCastException.
After I redeploy portlet B, it works again.
However, using portlet A again will get the same ClassCastException.

Does anyone know the cause of problem?
Thanks.
Terry AY,修改在12 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

New Member 帖子: 3 加入日期: 11-5-30 最近的帖子
Hi all,

My problem has been fixed.
Here's the solution to my problem:
http://www.liferay.com/zh/community/wiki/-/wiki/Main/Using+Class+Loader+Proxy+classes+to+share+plugins+services

The idea is "If 2 or more custom portlets use same set of entity(e.g. access same set of DB table) generated from service builder, only 1 portlet-service.jar(auto generated in docroot\WEB-INF\lib\) should be deployed to server. Otherwise, "ClassCastException" would be raised."

I used method 2(II) from the article and works fine.
Based on its concept, I first create a new portlet project (common.war) to centralize all entities to be accessed by other portlets. Then put the built portlet-service.jar as a common jar to {server}\lib\ext. During development, other portlet (other.war) should also create a service.xml and modify the ServiceImpl as usual. Before deployment, make sure to delete portlet-service.jar in docroot\WEB-INF\lib of common.war and other.war.

Hope can help if someone reached his thread.
Or, any better alternatives for my case? Thanks emoticon
thumbnail
N. Belo,修改在12 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 09-3-17 最近的帖子
Hi,

I also have this anoying problem. I am using Liferay 6 with Tomcat 6 Bundle, and the...

19:12:43,717 ERROR [jsp:154] java.lang.ClassCastException: com.myProject.service.model.impl.myClassImpl cannot be cast to com.myProject.service.model.myClass is driving me crazy.

If I remove the imported jar from /WEB-INF/lib in my portlet where should I put the Jar's so they can be shared through all portlets???

I have developed somre projects in Liferay 5.2.3 with Tomcat 6 and i hadn't any of this problems. Liferay 6 seems a less tested project.

Any sugestions??? Or should I go to 5.2.3 ???

Thanks in advance,
NB
thumbnail
Thiago Leão Moreira,修改在12 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Liferay Legend 帖子: 1449 加入日期: 07-10-10 最近的帖子
Hi NB,

You should promote your myproject-portlet-service.jar to the global classloader of Tomcat (tomcat-6.0.26/lib/ext). That's it. Don't forget to remove any reference to this jar in your portlets' war.
thumbnail
N. Belo,修改在12 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 09-3-17 最近的帖子
Thank you Thiago for the reply.

I've got the Same error. I'am calling myproject-portlet-service.jar in two portlets. At the first works fine, At the second keeps catching that Exception.

Thanks,
NB
Terry AY,修改在12 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

New Member 帖子: 3 加入日期: 11-5-30 最近的帖子
Hi NB

First to make sure 2 portlet WARs do not include any jar referring the Impl class.

I also suggest:
1) to clean and restart the portal before deploying 2 WARs.
2) uninstall the previous 2 portlets before deploying the new developed WARs
3) try not to use hot deploy, but use the upload plugin in Control Panel

Let see if can help.
thumbnail
N. Belo,修改在12 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Junior Member 帖子: 33 加入日期: 09-3-17 最近的帖子
Hi Terry,

thank you for your reply.
I've tried also that, and the same java.lang.ClassCastException it's trowed.

Besides, I am litle bit disapointed because I miss the good Integration between Netbeans 6.8 + Portal Pack 3.0.x with Liferay 5.2.

Eclipse was never my IDE because I've missed all that good GUI provided with portal pack for service.xml design and service generation.

And now, that the Oracle is pulling the strings for Mysql + NetBeans, etc... I feel, I have to make other options.

Thanks,
NB
thumbnail
Neil Griffin,修改在12 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

Liferay Legend 帖子: 2655 加入日期: 05-7-27 最近的帖子
FWIW, I saw a ClassCastException similar to this today when the following was present in the WEB-INF/liferay-portlet.xml descriptor:

<private-request-attributes>false</private-request-attributes>


According to the Liferay FAQ Wiki page:

"This method can possibly result in a ClassCastException (especially for multiple portlets in multiple WARs) and is therefore not recommended"
Alexander Akreev,修改在6 年前。

RE: [LF 6.0.5/JBoss] ClassCastException:ModelImpl cannot be cast to Model

New Member 发布: 1 加入日期: 17-2-14 最近的帖子
I found 2 solutions:
1) use CacheRegisteryUtil.clear() after working with models or use "Clear the database cache" in Server Administration to clear it manually.
2) Modell.class has been loaded by two different classloaders (used two model-service.jar with different paths). So you need to remove one of them.