RuntimeException: Unexpected global[] in Drools - java

I'm facing a problem using Spring with Drools. My main problem is that in the unit tests do not occur the error. Follows below the exception
java.lang.RuntimeException: Unexpected global [premioService]
This error occurs when I try to set a global variable in KieSession
Seeing the method StatefulKnowledgeSessionImpl#setGlobal(String, Object) seems that I should set the
globals before create a newInstance. Follows the StatefulKnowledgeSessionImpl#setGlobal code:
public void setGlobal(final String identifier,
final Object value) {
// Cannot set null values
if ( value == null ) {
return;
}
try {
this.kBase.readLock();
startOperation();
// Make sure the global has been declared in the RuleBase
final Map globalDefintions = this.kBase.getGlobals();
final Class type = (Class) globalDefintions.get( identifier );
if ( (type == null) ) {
throw new RuntimeException( "Unexpected global [" + identifier + "]" );
} else if ( !type.isInstance( value ) ) {
throw new RuntimeException( "Illegal class for global. " + "Expected [" + type.getName() + "], " + "found [" + value.getClass().getName() + "]." );
} else {
this.globalResolver.setGlobal( identifier,
value );
}
} finally {
endOperation();
this.kBase.readUnlock();
}
}
Follows my code:
#Inject
protected PremioVisaoService premioVisaoService;
protected final KieSession createSession() {
return this.kieBase.newKieSession();
}
protected final int process() {
final KieSession kieSession = this.createSession();
Object rulesFired = 0;
try {
//here occurs the error
kieSession.execute(CommandFactory.newSetGlobal(PREMIO_SERVICE_GLOBAL_ID, premioVisaoService));
} catch(Exception e) {
e.printStackTrace();
}
}
package br.com.company.brms.model.rules;
import br.com.company.brms.model.*;
import br.com.company.brms.model.premios.*;
import br.com.company.brms.model.tarifas.*;
import function br.com.company.brms.helpers.DomainUtils.getPais;
import function br.com.company.brms.helpers.DomainUtils.getUF;
import function br.com.company.brms.helpers.PremioFactory.novoPremioVisaoPercursoPadrao;
import function br.com.company.brms.helpers.CalculoTarifaHelper.calculaTaxaBasica;
global br.com.company.brms.services.PremioVisaoService premioService;
rule "Rule Example"
ruleflow-group "calculo"
salience -1
when
$averbacao : Averbacao( indicadorAvaria == Constantes.STATUS_SIM )
$taxa : TarifaPercursoVigencia( tipoTarifa == TipoTarifa.AVARIA)
then
PremioVisaoPercursoPadrao premio = novoPremioVisaoPercursoPadrao($taxa, $averbacao);
premio.setValor( calculaTaxaBasica($taxa, $averbacao) );
//insert ( premio );
premioService.inserirPremioCalculado( premio );
//System.out.println( $averbacao + " calculada com o premio: " + premio );
end
Follows below the stacktrace:
java.lang.RuntimeException: Unexpected global [premioService]
at org.drools.core.impl.StatefulKnowledgeSessionImpl.setGlobal(StatefulKnowledgeSessionImpl.java:1124)
at org.drools.core.command.runtime.SetGlobalCommand.execute(SetGlobalCommand.java:65)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.execute(StatefulKnowledgeSessionImpl.java:665)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.execute(StatefulKnowledgeSessionImpl.java:648)
at br.com.company.brms.services.impl.BilhetagemBpmnRunnerServiceImpl.processar(BilhetagemBpmnRunnerServiceImpl.java:87)
at br.com.company.brms.services.impl.BilhetagemBpmnRunnerServiceImpl.processarRegrasMercado(BilhetagemBpmnRunnerServiceImpl.java:52)
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:317)
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$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy68.processarRegrasMercado(Unknown Source)
at br.com.company.brms.services.impl.BilhetagemProcessManagerServiceImpl.processar(BilhetagemProcessManagerServiceImpl.java:111)
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:317)
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$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy69.processar(Unknown Source)
at br.com.company.brms.spi.impl.BilhetagemServiceAsyncImpl.processarPorCliente(BilhetagemServiceAsyncImpl.java:88)
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:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:95)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Tks in advance

My problem was that I were looking for the DRL files in different jars. I don't know yet how I'll do this in the right way. But the problem definitely was solved.

I finally tracked down what the root cause of this is:
If you have a rule and you want to setGlobal for that rule, you must have the global defined in that rule (the .drl file), such as;
global net.mikeski.ProviderImpl provider
Then, kSession.setGlobal("provider", myProviderImpl); will work.
I discovered this by looking at the Drools setGlobal method in StatefulKnowledgeSessionImpl.java:
...
final Class type = (Class) globalDefintions.get( identifier );
if ( (type == null) ) {
throw new RuntimeException( "Unexpected global [" + identifier + "]" );
} else if ( !type.isInstance( value ) ) {
throw new RuntimeException( "Illegal class for global. " + "Expected [" + type.getName() + "], " + "found [" + value.getClass().getName() + "]." );
} else {
this.globalResolver.setGlobal( identifier,
value );
}
...

Related

Need Eclipse IDE Plugin Dev Help: Rename File Resource of the Active Editor, TextEditor

From a plug-in in Eclipse, I have bound a key combination to attempt to use the Project Explorer refactor dialog to rename a file resource that is being edited by a TextEditor. The editor is the active selected view at the time. I am so far unsuccessful.
If I bind another key combination to the same command ID, that is "org.eclipse.ui.edit.rename", Then manually select the file resource in the Project Explorer and do the key sequence, the dialog does indeed present itself. Does this imply that I need to programatically give the Project Explorer focus?
Can anyone offer suggestions how I can programatically refactor/rename the resource associated with the active editor? I don't want to do "Save As" as this commits the change to disk and I don't want to force the user to do that yet.
The following is my test code called by the handler for the custom key binding command.
public Object execute( ExecutionEvent event ) throws ExecutionException
{
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked( event );
if( window == null ) return null;
IWorkbenchPage workbench_page = window.getActivePage();
if( workbench_page == null ) return null;
IEditorPart active_editor = workbench_page.getActiveEditor();
if( !( active_editor instanceof ITextEditor ) ) return null;
// Not used here yet...
StyledText styled_text = (StyledText)( (ITextEditor)active_editor).getAdapter( Control.class );
Display display = styled_text.getDisplay();
switch( event.getCommand().getId() )
{
case "test.commands.sampleCommand":
{
IViewPart view_part = workbench_page.findView( "org.eclipse.ui.navigator.ProjectExplorer" );
if( ( view_part != null ) && ( view_part instanceof ProjectExplorer ) )
{
// Try and select the resource. This does not seem to do anything visually...
IPath path = ( (IPathEditorInput)active_editor.getEditorInput() ).getPath();
if( path == null ) return null;
( (ISetSelectionTarget)view_part ).selectReveal( new StructuredSelection( path ) );
ICommandService command_service = ( (ProjectExplorer)view_part ).getViewSite().getService( ICommandService.class );
if( command_service == null ) return null;
Command file_rename_command = command_service.getCommand( IWorkbenchCommandConstants.FILE_RENAME );
try
{
// Rename the selected resource.
file_rename_command.executeWithChecks( new ExecutionEvent() );
}
catch( NotDefinedException | NotEnabledException | NotHandledException exception )
{
log_error( "Did not work :", exception );
return null;
}
log_info( "Success :" + view_part.toString() );
}
return null;
}
default: return null;
}
}
The following is the resultant debug log output.
!ENTRY test 1 0 2019-12-19 09:47:06.902
!MESSAGE Did not work :
!STACK 0
org.eclipse.core.commands.NotHandledException: There is no handler to execute for command org.eclipse.ui.edit.rename
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:511)
at test.Activator.execute(Activator.java:125)
at test.handlers.SampleHandler.execute(SampleHandler.java:18)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:283)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:318)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:252)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:173)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:156)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:498)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:487)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:213)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:308)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:584)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:653)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:443)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.access$2(KeyBindingDispatcher.java:386)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:96)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1199)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1056)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1081)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1108)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1104)
at org.eclipse.swt.widgets.Widget.wmKeyDown(Widget.java:1759)
at org.eclipse.swt.widgets.Control.WM_KEYDOWN(Control.java:5146)
at org.eclipse.swt.widgets.Canvas.WM_KEYDOWN(Canvas.java:414)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4793)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:348)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4820)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(Native Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3583)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1160)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1049)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:633)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:557)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:137)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:107)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:660)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:597)
at org.eclipse.equinox.launcher.Main.run(Main.java:1468)
at org.eclipse.equinox.launcher.Main.main(Main.java:1441)
Thanks and BR,
Ralph
PS,
Full discosure, I asked this question in the eclipse forums also.

EasyMock unexpected method call

I can't work out how to setup the expectation of a call to a mock class. Here is the JUnit test:
public class AfkTest extends TestCase {
private AfkPlayerManager manager;
private Player player;
private Set<AfkPlayer> afkPlayers;
public void setUp() throws Exception {
super.setUp();
manager = new AfkPlayerManager();
player = EasyMock.createMock(Player.class);
afkPlayers = new HashSet<AfkPlayer>();
}
public void tearDown() {
}
public void testNotifyOfAfkPlayerSuccess() {
AfkPlayer afkPlayer = new AfkPlayer();
afkPlayer.setPlayer(player);
afkPlayer.setReason("TEST REASON");
afkPlayers.add(afkPlayer);
List<Player> onlinePlayers = new ArrayList<Player>();
onlinePlayers.add(player);
onlinePlayers.add(player);
EasyMock.expect(player.getDisplayName()).andReturn("TEST PLAYER");
player.sendMessage("§9TEST PLAYER§b is AFK. [TEST REASON]");
EasyMock.expectLastCall().times(1);
//activate the mock
EasyMock.replay(player);
assertTrue(manager.notifyOfAfkPlayer(onlinePlayers, afkPlayer));
//verify call to sendMessage is made or not
EasyMock.verify(player);
}
}
And the method that I am testing:
public class AfkPlayerManager implements Manager {
public boolean notifyOfAfkPlayer(Collection<Player> onlinePlayers, AfkPlayer afkPlayer) {
if (afkPlayer == null) {
return false;
}
String message = ChatColor.BLUE + afkPlayer.getPlayer().getDisplayName();
message += ChatColor.AQUA + " is AFK.";
if (afkPlayer.getReason().length() > 0) {
message += " [" + afkPlayer.getReason() + "]";
}
if (onlinePlayers != null && onlinePlayers.size() > 1) {
int notified = 0;
for (Player onlinePlayer : onlinePlayers) {
onlinePlayer.sendMessage(message);
notified++;
}
if (notified > 0) {
return true;
}
}
return false;
}
}
Why is this giving me the AssertionError:
java.lang.AssertionError: Unexpected method call
Player.sendMessage("§9TEST PLAYER§b is AFK. [TEST REASON]"):
Player.sendMessage("§9TEST PLAYER§b is AFK. [TEST REASON]"): expected: 1, actual: 0 at
org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:44)
at
org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:94)
at com.sun.proxy.$Proxy3.sendMessage(Unknown Source) at
crm.afk.AfkPlayerManager.notifyOfAfkPlayer(AfkPlayerManager.java:33)
at crm.test.AfkTest.testNotifyOfAfkPlayerSuccess(AfkTest.java:84) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.lang.reflect.Method.invoke(Unknown Source) at
junit.framework.TestCase.runTest(TestCase.java:176) at
junit.framework.TestCase.runBare(TestCase.java:141) at
junit.framework.TestResult$1.protect(TestResult.java:122) at
junit.framework.TestResult.runProtected(TestResult.java:142) at
junit.framework.TestResult.run(TestResult.java:125) at
junit.framework.TestCase.run(TestCase.java:129) at
junit.framework.TestSuite.runTest(TestSuite.java:252) at
junit.framework.TestSuite.run(TestSuite.java:247) at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
The expected and actual are different.
Expected: §9TEST PLAYER§b is AFK. [TEST REASON]
Actual: §9TEST PLAYER§b is AFK. [TEST REASON]
The  at the beginning is missing. So it fails as it should.

Minecraft One Player Per Config

I'm going to try to make this quick basically i'm trying to make ONE config per player.
So basically when ever I call user.CreateUser(); if the user doesn't exist it registers there own config with there unique id as the name of the yml
My problem is that when ever I try to call user.CreateUser(); on the PlayerJoinEvent it shows a error and i'm not sure the UUID u shouldn't be returning null because it's inside a constructor or the other variables.
Error
[23:57:52 ERROR]: Could not pass event PlayerJoinEvent to MCEnhanced v1.0
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
va:310) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
a:62) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
ava:502) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
ava:487) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:
296) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:156) [spigo
t-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:144)
[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:54) [
spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:231
) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.ServerConnection.c(ServerConnection.java
:148) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:8
17) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
67) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
57) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
:560) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
Caused by: java.lang.NullPointerException
at crypted.mcenhanced.Handlers.UserDataHandler.CreateUser(UserDataHandle
r.java:46) ~[?:?]
at crypted.mcenhanced.Mechanics.ConfigMechanics.CreateUser.CreateUser(Cr
eateUser.java:19) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
.8.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
va:306) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
... 14 more
CreateUser Listener Class
public class CreateUser implements Listener {
#EventHandler
public void CreateUser(PlayerJoinEvent event){
Player player = event.getPlayer();
UserDataHandler user = new UserDataHandler(player.getUniqueId());
user.CreateUser();
}
}
UserDataHandler Class
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.Listener;
import java.io.File;
import java.util.UUID;
public class UserDataHandler implements Listener {
UUID u;
File UserFile;
FileConfiguration UserConfig;
//UserDataHandler user = new UserDataHandler(player.getUniqueId()); // Make sure that you have the player.getUniqueId()
public UserDataHandler(UUID u){
this.u = u;
File UserFile = new File("plugins/MCEnhanced/data/" + u + ".yml");
YamlConfiguration UserConfig = YamlConfiguration.loadConfiguration(UserFile);
}
public void CreateUser(){
if ( !(UserFile.exists()) ) {
try {
//Bukkit.getConsoleSender().sendMessage(ChatColor.YELLOW + "[MCEnhanced] Created a new File for " + player.getName() + "(" + player.getUniqueId() + ")");
YamlConfiguration UserConfig = YamlConfiguration.loadConfiguration(UserFile);
UserConfig.save(UserFile);
} catch (Exception e) {
e.printStackTrace();
// Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[MCEnhanced] Could not create a new File for " + player.getName() + "(" + player.getUniqueId() + ")");
//u.kickPlayer(ChatColor.RED + "We could not create a file for your account!"); // THE PLAYERS CONFIG NEEDS TO BE CREATED!!!!!!!!
}
}
}
public FileConfiguration getUserFile(){
return UserConfig;
}
public void setDefaultUserFile(){
getUserFile().set("MCEnhanced.Info.IsInfected", false);
}
public void saveUserFile(){
try {
getUserFile().save(UserFile);
} catch(Exception e) {
e.printStackTrace();
}
}
}
In the CreateUser method, you are referencing the UserFile field or instance variable of the current UserDataHandler object which is by default null. Your constructor for the UserDataHandler class does not instantiate this UserFile field and instead creates a local File variable inside that constructor which is then never used. The line...
File UserFile = new File("plugins/MCEnhanced/data/" + u + ".yml");
should be...
UserFile = new File("plugins/MCEnhanced/data/" + u + ".yml");
so that the File field is instantiated for that instance.
I would recommend using the lowerCamelCase naming convention to name your variables, fields and methods as well.

java.lang.ClassNotFoundException: org.jpos.iso.ISOException

I'm beginner for using JPOS with ISO8583. At this time, I try my application using Spring to build the request using JPOS where I want to send it to BASE24.
Here my code for build :
public class BuildISO {
public void sentISOMsg(String hostname, int portNumber) {
// Create Packager based on XML that contain DE type
GenericPackager packager;
ASCIIChannel channel;
try {
packager = new GenericPackager("packager/iso93ascii.xml");
channel = new ASCIIChannel(hostname, portNumber, packager);
ISOMUX isoMux = new ISOMUX(channel) {
#Override
protected String getKey(ISOMsg m) throws ISOException {
return super.getKey(m);
}
};
new Thread(isoMux).start();
// Create ISO Message
ISOMsg isoRequest = new ISOMsg();
isoRequest.setMTI("1800");
isoRequest.set(3, "123456");
isoRequest.set(7, new SimpleDateFormat("yyyyMMdd").format(new Date()));
isoRequest.set(11, "000001");
isoRequest.set(12, new SimpleDateFormat("HHmmss").format(new Date()));
isoRequest.set(13, new SimpleDateFormat("MMdd").format(new Date()));
isoRequest.set(48, "Tutorial ISO 8583 Dengan Java");
isoRequest.set(70, "001");
ISORequest req = new ISORequest(isoRequest);
isoMux.queue(req);
ISOMsg isoReply = req.getResponse(50*1000);
if (isoReply != null) {
System.out.println("Req ["+new String(isoRequest.pack()) + "]");
System.out.println("Res ["+new String(isoReply.pack()) + "]");
}
// print the DE list
logISOMsg(isoRequest);
// Get and print the output result
byte[] data = isoRequest.pack();
System.out.println("RESULT : " + new String(data));
} catch (ISOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static void logISOMsg(ISOMsg msg) {
System.out.println("----ISO MESSAGE-----");
try {
System.out.println(" MTI : " + msg.getMTI());
for (int i=1;i<=msg.getMaxField();i++) {
if (msg.hasField(i)) {
System.out.println(" Field-"+i+" : "+msg.getString(i));
}
}
} catch (ISOException e) {
e.printStackTrace();
} finally {
System.out.println("--------------------");
}
}
}
and next, while I want to call that class in here :
public #ResponseBody ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
String hostname = request.getParameter("hostname");
int portNumber = Integer.parseInt(request.getParameter("portNumber"));
System.out.println("handleRequest... : " + hostname + " : " + portNumber);
BuildISO buildISO = new BuildISO();
buildISO.sentISOMsg(hostname, portNumber);
return null;
}
I got error like this :
SEVERE: Servlet.service() for servlet spring threw exception
java.lang.ClassNotFoundException: org.jpos.iso.ISOException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at org.sprint.controller.HandleController.handleRequest(HandleController.java:28)
at org.sprint.controller.HandleController$$FastClassByCGLIB$$fc3d18c.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.interceptor.CustomizableTraceInterceptor.invokeUnderTrace(CustomizableTraceInterceptor.java:256)
at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
at org.sprint.controller.HandleController$$EnhancerByCGLIB$$fbdc3830.handleRequest(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
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.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:722)
I have searched through StackOverflow's already asked questions, but have not found any of the situations in which the changes to the project were NONE. So I am feeling quite frustrated now because I have actually changed NOTHING and my project has stopped working. Help me please, any ideas would be grateful.
You should be sure that you have all jars in the CLASSPATH. In your case it is jpos.jar. And they all (with Spring) should be loaded withing the same classloader.
And one more advice: add -verbose option to the java (I guess Tomcat) to see from where your classes are loaded.
Please add the maven jpos dependency to you project.
<dependency>
<groupId>org.jpos</groupId>
<artifactId>jpos</artifactId>
<version>1.9.4</version>
</dependency>
Choose any one of the repository available from maven Maven Repository Link

Hibernate JPA delete entity with cascade (deleted entity passed to persist)

I have searched for and read/studied almost every link on the web concerning problems with deleting parent entities and having the delete cascade through my OneToMany collections. I have tried many of the suggestions, including removing all references to the contained collection, different Cascade type combinations, etc. Still when I try to delete a parent entity, I continually get an exception on persisting a deleted entity.
I have an Adhesive entity class which contains a OneToMany relationship with AdhesiveChemicals like this:
#Entity
#Table(name = "Adhesive")
#NamedQueries({
public class Adhesive implements Serializable {
private static final long serialVersionUID = 1L;
// #Max(value=?) #Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
private Long adhesiveId;
private String adhesiveName;
private String costPerDryPound;
private String solidPercent;
private String totalActCost;
private String totalDry;
private String totalWet;
private Boolean inactive;
private List<AdhesiveChemicals> adhesiveChemicals;
private List<AdhesiveComponent> adhesiveComponentsList;
#OneToMany(cascade= {CascadeType.REMOVE, CascadeType.MERGE, CascadeType.REFRESH}, mappedBy="adhesive", targetEntity=AdhesiveChemicals.class, orphanRemoval=true)
#LazyCollection(LazyCollectionOption.FALSE)
public List<AdhesiveChemicals> getAdhesiveChemicalsList() {
return adhesiveChemicals;
}
public void setAdhesiveChemicalsList(List<AdhesiveChemicals> adhesiveChemicals) {
this.adhesiveChemicals = adhesiveChemicals;
}
#OneToMany(mappedBy="adhesive", targetEntity=AdhesiveComponent.class)
#LazyCollection(LazyCollectionOption.FALSE)
public List<AdhesiveComponent> getAdhesiveComponentsList() {
return adhesiveComponentsList;
}
public void setAdhesiveComponentsList(List<AdhesiveComponent> adhesiveComponentsList) {
this.adhesiveComponentsList = adhesiveComponentsList;
}
#Override
public int hashCode() {
int hash = 0;
hash += (adhesiveId != null ? adhesiveId.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Adhesive)) {
return false;
}
Adhesive other = (Adhesive) object;
if ((this.adhesiveId == null && other.adhesiveId != null) || (this.adhesiveId != null && !this.adhesiveId.equals(other.adhesiveId))) {
return false;
}
return true;
}
#Override
public String toString() {
return "Adhesive{" + "adhesiveId=" + adhesiveId + ", adhesiveName=" + adhesiveName +
", costPerDryPound=" + costPerDryPound + ", solidPercent=" + solidPercent +
", totalActCost=" + totalActCost + ", totalDry=" + totalDry + ", totalWet=" +
totalWet + ", inactive=" + inactive + '}';
}
}
The AdhesiveChemicals class:
#Entity
public class AdhesiveChemicals implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String wetLbs;
private String dryLbs;
private String actualCost;
private Adhesive adhesive;
private Chemical chemical;
#ManyToOne(fetch= FetchType.EAGER, optional=false)
#JoinColumn(name="adhesive_id")
public Adhesive getAdhesive() {
return adhesive;
}
public void setAdhesive(Adhesive adhesive) {
this.adhesive = adhesive;
}
#ManyToOne(fetch = FetchType.EAGER, optional=false)
#JoinColumn(name="chemical_id")
public Chemical getChemical() {
return chemical;
}
public void setChemical(Chemical chemical) {
this.chemical = chemical;
}
#Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
#Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof AdhesiveChemicals)) {
return false;
}
AdhesiveChemicals other = (AdhesiveChemicals) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
#Override
public String toString() {
return "AdhesiveChemicals{" + "wetLbs=" + wetLbs + ", dryLbs=" + dryLbs
+ ", actualCost=" + actualCost + ", adhesive=" + adhesive + ", chemical=" + chemical + '}';
}
The code that is called to delete the Adhesive is here:
// Handler for Button[fx:id="pricingAdhesiveDeleteButton"] onMouseClicked
public void doAdhesiveDelete(MouseEvent event) {
// handle the event here
logger.info("Entering {}.doAdhesiveDelete.", this.getClass().getName());
if (pricingAdhesiveTable.getSelectionModel().getSelectedIndex() < 0) {
return;
}
DialogFX dialog = new DialogFX(DialogFX.Type.QUESTION);
dialog.setTitleText("Delete?");
dialog.setMessage(" Do you really wish to delete " + tempAdhesive.getAdhesive() + "? ");
if (dialog.showDialog() == 1) {
return;
}
tempAdhesive.getAdhesiveChemicalsList().clear();
pricingAdhesiveTableList.remove(tempAdhesive);
// for (AdhesiveChemicals adhesiveChemicals : acList) {
// costingService.removeAdhesiveChemicals(adhesiveChemicals.getId());
// }
costingService.removeAdhesive(tempAdhesive.getId());
init();
pricingAdhesiveDeleteButton.setDisable(true);
}
The costingService is a Glassfish service which has implementations of all of the create/update/delete methods on the database. The removeAdhesive method looks like this:
#Service
#Transactional(readOnly=false)
public class CostingServiceImpl implements CostingService {
private static final Logger logger = LoggerFactory.getLogger(CostingServiceImpl.class.getName());
private EntityManager em;
#PersistenceContext(name="LamtecVoyagerPU")
public void setEntityManager(EntityManager entityManager) {
this.em = entityManager;
}
#Override
public void removeAdhesive(Long Id) {
logger.info("Entering {}.removeAdhesive.", this.getClass().getName());
Adhesive a = em.find(Adhesive.class, Id);
// a.getAdhesiveChemicalsList().clear();
em.remove(a);
}
As you can see, at this point I have cascading limited to REFRESH, MERGE and REMOVE on the one to many relationship and I have orphan removal set to true. However, when I try to delete an adhesive which contains some AdhesiveChemicals, the following exception is thrown. (There is some extra stuff in there that has to do with the communication between the client and the server.)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1440)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3113)
at javafx.scene.Scene$ClickGenerator.access$8600(Scene.java:3051)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3333)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3164)
at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3119)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1559)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2261)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:228)
at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
at com.sun.glass.ui.View.notifyMouse(View.java:922)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1435)
... 31 more
Caused by: org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: Transaction marked for rollback.
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1012)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy463.removeAdhesive(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
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.remoting.support.RemoteInvocationTraceInterceptor.invoke(RemoteInvocationTraceInterceptor.java:77)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy464.removeAdhesive(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:205)
at org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:38)
at org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:78)
at org.springframework.remoting.support.RemoteInvocationBasedExporter.invokeAndCreateResult(RemoteInvocationBasedExporter.java:114)
at org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter.handleRequest(HttpInvokerServiceExporter.java:73)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:585)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
at org.springframework.remoting.support.RemoteInvocationUtils.fillInClientStackTraceIfPossible(RemoteInvocationUtils.java:47)
at org.springframework.remoting.support.RemoteInvocationResult.recreate(RemoteInvocationResult.java:115)
at org.springframework.remoting.support.RemoteInvocationBasedAccessor.recreateRemoteInvocationResult(RemoteInvocationBasedAccessor.java:85)
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:148)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy14.removeAdhesive(Unknown Source)
at com.lamtec.pricingclient.PricingPresenter.doAdhesiveDelete(PricingPresenter.java:982)
... 36 more
Caused by: javax.transaction.RollbackException: Transaction marked for rollback.
at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:473)
at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:855)
at com.sun.enterprise.transaction.UserTransactionImpl.commit(UserTransactionImpl.java:208)
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1009)
... 102 more
Caused by: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.lamtec.lamteccommon.data.costing.AdhesiveChemicals#<null>]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1369)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1315)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1321)
at org.hibernate.ejb.AbstractEntityManagerImpl$3.mapManagedFlushFailure(AbstractEntityManagerImpl.java:1235)
at org.hibernate.transaction.synchronization.CallbackCoordinator.beforeCompletion(CallbackCoordinator.java:122)
at org.hibernate.transaction.synchronization.HibernateSynchronizationImpl.beforeCompletion(HibernateSynchronizationImpl.java:51)
at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:435)
... 105 more
The original query which populates the list containing Adhesives (and by default due to eager fetching, the AdhesiveChemicals):
#Override
public List<Adhesive> listAdhesives() {
logger.info("Entering {}.listAdhesives.", this.getClass().getName());
Query query = em.createNamedQuery("Adhesive.findAll");
List<Adhesive> result = new ArrayList<>();
try {
result = query.getResultList();
} catch (Exception ex) {
logger.info("Not able to get Adhesive list");
throw ex;
}
return result;
}
The results of this are placed in the pricingAdhesiveTableList. When I try to remove the adhesive to be deleted, I remove it from the pricingAdhesiveTableList also, as can be seen in the doAdhesiveDelete code above.
Please don't worry about my feelings. I have already beaten myself up pretty good over this one. I have many other deletes that are working fine, but this one continues to perplex me. If you need any more information, please let me know.
Oh, the database is MS SQL Server and I'm using Hibernate 3.6 for my JPA provider. Glassfish is version 3.X.
Thanks.

Categories