Java: exception when casting to itself(?) - netbeans

Im working with Oracle WebLogic, Netbeans 6.9.1.
I have the following lines of code:
Query query=entityManager.createNamedQuery("Items.findById").setParameter("id", Integer.parseInt((String) request.getParameter("id")));
Items it=(Items) query.getSingleResult();
and they throw an exception:
java.lang.ClassCastException: entity.Items cannot be cast to entity.Items
Even if that seem impossible, i saw similar question on SO: here
Author havent published the solution but one of participants made a good asumption about different class loaders.
Meanwhile if i use getResultList and then work with it in JSP, it works fine. But i cant make casting work in servlet code.
How can i fix this in weblogic?

It doesn't solve your problem specifically, but if you're using WebLogic Server 10.3.x or thereabouts, there is a web application provided as part of that distribution that you can use to troubleshooting classloading issues.
You can read more about it here: http://download.oracle.com/docs/cd/E17904_01/web.1111/e13706/classloading.htm#WLPRG495
It should be compatible with earlier versions of WebLogic Server, so you could use that in conjunction with the proposed workarounds to get to a solution.

See this similiar question with a proposed workaround.

This indeed looks like a classloading problem.
This earlier answer of mine explains how to verify this assumption.
Unfortunately, classloading problems are difficult and painful. There is no easy fix, only to try to understand what classloaders are loading what classes in which order, and trying to play around with your classloaders, classes and jars to eliminate the problem. Also, analyse the most recent changes in your app before this error appeared - these can provide the key to understanding the root cause.
I am not familiar with the classloading scheme in WebLogic, so unfortunately I can't give you any more specific advice.

Related

Drools doesn't work with spring-boot-devtools

When we have spring-boot-devtools on pom.xml the drools rules dont work. There are no error but the drools rules dont get fired at all. After excluding the spring-boot-devtools the drools rule start working.
There's a documented issue about a classloading problem while using spring-boot devtools together with drools: DROOLS-1540
As specified in spring-boot reference documentation you can add jars to the devtools "reloading" classloader as a workaround.
META-INF/spring-devtools.properties
restart.include.drools-core=/drools-core-7.0.0.Final.jar
restart.include.drools-compiler=/drools-compiler-7.0.0.Final.jar
restart.include.kie-api=/kie-api-7.0.0.Final.jar
restart.include.kie-ci=/kie-ci-7.0.0.Final.jar
restart.include.kie-internal=/kie-internal-7.0.0.Final.jar
Be careful to use YOUR exacts jar and eventually add other libraries directly referenced in your rules files.
(for moderator) flgged Drools rule does't working in Spring Boot Controller but working in Junit Test as duplicated of this question and removed the answer on that post
Really strange problem indeed. As far as I can tell, there are 2 issues here:
Apparently, the KieFileSystem doesn't play well with org.springframework.boot.devtools.restart.classloader.RestartClassLoader. Even if I tried passing the DRL as a String, it didn't take it.
Even if I managed to get a populated KieBase using a kmodule.xml file, the rules were still not firing. My guess is that the classloader at some points changes the definition of the classes, so when you insert a Product object, its class is no longer the same as the Product class that is being used by the DRL. Another possibility is that there are multiple classloaders in play. Take a look at this question and at this document.
Unfortunately, I was not able to find a way to make it work. I hope the information I've provided helps you.

Scala ClassNotFoundException Random Constant

I have quite a few mixed scala and java projects. They will run just fine up to some seemingly random time when they don't.
Compile goes fine, with zero errors or warnings, yet on run I get the infamous
ClassNotFoundException
In this current project I have only Scala files, and I deleted all of them and left it at a simple Test object with main method.
YET IT STILL SAYS ClassNotFoundException
I have scoured the net, and tried everything I have found.
Has anyone had this experience, and moreover, are there any suggestions?
Are you trying to run a run configuration for a class that have been deleted? If you're using Intellij and pressing Shift-F10 it will happily try to run a configuration even though the class does not exist anymore.
My other related question actually provides more insight and provides a solution to this problem.
Running Objects in Play 2.0 Framework
Hope it helps when everyone is using Scala in a few years...

System.Data.MetadataException - seems more stubborn than most people's

I have gone through this post and the links, and still can't solve my issue.
I have changed my config to name the assembly, but it makes no odds.
We recently moved the projects and think that might be an issue - but how to solve it if so. I don't quite understand how EF when running finds the cdsl etc. files I thought they were embedded in the dll [it is set to do so]?
The service having the issue doesn't directly use EF itself, it uses another DLL which DOES. I also added a direct ref to the DLL but no joy.
Also, the same code (the dll that contains the functionality, not the wrapper service) using the same connections strings works fine in my system test project via the IDE.
Turned out to be down to incorrect initialisation of StructureMap and not really to do with EF itself.

Create RMI stubs

I am using Netbeans 6.9.1. I want to create a stub for my server class. I got stuck there. Browsing through several StackOverflow forums, i found varied answers, which ranged from "no need of creating a stub" to "modify the build.xml". I tried the latter, but it did not work. Can someone please tell me what I should do? Is there any plugin of some sort that I can use? (I did not find any)
http://netbeans.org/projects/rmi/ shows a 404 error. :(
Vikram.
I want to create a stub for my server
class.
Why? Stubs haven't been needed since 1.5 came out, many years ago now.

TargetInvocationException when calling performFinish() on any subclass of NewItemWizard in Eclipse JDT UI plugins

I'm posting this on behalf of the 30 or so projects that seem to be suffering from this problem without any resolution.
Basically the problem boils down to, a subclass of org.eclipse.jdt.internal.ui.wizards.NewElementWizard (which is the "Wizard" that controls the creation of new JDT elements like projects, packages, classes, etc -- this problem seems to happen no matter what reason you're subclassing for) overloads performFinish() and calls super.performFinish() as part of that call. So far so good, but for some reason if this happens on an empty workspace (which is often the case for new projects), the super.performFinish() call fails with an exception similar to the following:
java.lang.reflect.InvocationTargetException
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:350)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:851)
at org.eclipse.jdt.internal.ui.wizards.NewElementWizard.performFinish(NewElementWizard.java:133)
at com.canoo.wizard.newproject.NewULCProjectWizard.performFinish(NewULCProjectWizard.java:118)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:680)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:355)
at org.eclipse.jface.dialogs.Dialog$3.widgetSelected(Dialog.java:660)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
or something similar to that -- the error is strikingly similar across dozens of different projects that I've found in the process of Google'ing about for this error, whether the subclass of the NewItemWizard happens to be a Project Wizard, a Class Wizard, whatever.
Some of the people reporting this problem later post that it was caused by a "version mismatch" but, maddeningly, they never give any details as to what versions were mistmatching with what -- and I've tried my code on Linux, Windows, and OS X so I doubt it's some very version-or-platform-specific nuance.
Lastly, there does not seem to be anything in the Eclipse bugzilla even tangentially related to this problem.
Has anyone run into this before, since it seems so ubiquitous? Any help would be greatly appreciated!
InvocationTargetException is a checked exception that wraps an exception thrown by an invoked method or constructor
Every case I have found report some kind of incompatibility between Eclipse and a module:
VE (Visual Editor) with this thread, or that one, or this GTK64 SWT issue.
bug 161621 (enum is a Keyword for Java5 and cannot be used as a Enum name), where the NewElement Wizard didn't reject enum as a class name on a 1.5 project.
In other words, this kind of exception is often the symptom of another issue.
The enum issue is a good example of such an incompatibility, but each time it can be a different problem related to the specific operations or configurations of the project.