You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by "M. Walter" <ma...@sbb.ch> on 2011/11/11 14:52:40 UTC
Strange behaviour on ManyToMany relationship using RCP client
In our (RCP) client/server application a JAR is packaged on both sides
containing all build time enhanced entities.
Now we have a ManyToMany relationship with a join table defined. When we add
both entities to each other to create a new relationship between two
entities a und b everything works fine on the server side.
But on the client side we get a very strange NullPointerException at a
position we thought a NPE is not possible. Please have a look at our code:
Entitiy A:
public void addB(final B b) {
if (bList == null) {
bList = new ArrayList<B>();
}
if (!bList.contains(b)) {
bList.add(b);
b.addA(this);
}
}
Entity B:
public void addA(final A a) {
if (aList == null) {
aList = new ArrayList<A>(); // this code is executed but aList
is not initialized. Why?
}
if (!aList.contains(a)) { // NullPointerException here!! aList is null!
aList.add(a);
a.addBp(this);
}
}
Does anyone have a hint why this is happening (and on client side only)?
--
View this message in context: http://openjpa.208410.n2.nabble.com/Strange-behaviour-on-ManyToMany-relationship-using-RCP-client-tp6985422p6985422.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Strange behaviour on ManyToMany relationship using RCP client
Posted by Rick Curtis <cu...@gmail.com>.
Walter -
Can you clarify the scenario a little? Are you seeing these anomalies when
Entities are created on the RCP side, then streamed to the server to
persist?
You mentioned that you aren't able to recreate this behavior in your JUnit
integration testing... are you serializing / deserializing your Entities in
those tests? That would recreate streaming them over the wire... which
might be where we're having problems.? That being said, nothing is coming
immediately to mind as to what the issue might be.
Thanks,
Rick
On Tue, Nov 15, 2011 at 5:55 AM, M. Walter <ma...@sbb.ch> wrote:
> Hi Rick,
>
> we found out another interesting thing. Under some conditions (i.e. using
> entities on RCP client side) saving the "right" entity matters. We called
> persist on the inverse side entity of the ManyToMany relationship which
> lead
> to only one UPDATE statement for the inverse entity. The expected INSERT
> statement on the join table wasn't executed. As we switched the owning and
> inverse side everything worked as expected. Two UPDATE and one INSERT
> statements were executed.
>
> But again there is something strange: for the JUnit integration test this
> does NOT matter apparently. Calling persist on the inverse side of the
> relationship executed all necessary statements in order to create the new
> ManyToMany relationship. Do you have an explanation for this behaviour?
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Strange-behaviour-on-ManyToMany-relationship-using-RCP-client-tp6985422p6996020.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
--
*Rick Curtis*
Re: Strange behaviour on ManyToMany relationship using RCP client
Posted by "M. Walter" <ma...@sbb.ch>.
Hi Rick,
we found out another interesting thing. Under some conditions (i.e. using
entities on RCP client side) saving the "right" entity matters. We called
persist on the inverse side entity of the ManyToMany relationship which lead
to only one UPDATE statement for the inverse entity. The expected INSERT
statement on the join table wasn't executed. As we switched the owning and
inverse side everything worked as expected. Two UPDATE and one INSERT
statements were executed.
But again there is something strange: for the JUnit integration test this
does NOT matter apparently. Calling persist on the inverse side of the
relationship executed all necessary statements in order to create the new
ManyToMany relationship. Do you have an explanation for this behaviour?
--
View this message in context: http://openjpa.208410.n2.nabble.com/Strange-behaviour-on-ManyToMany-relationship-using-RCP-client-tp6985422p6996020.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Strange behaviour on ManyToMany relationship using RCP client
Posted by Rick Curtis <cu...@gmail.com>.
Walter -
Thanks for the additional debug info.... I assumed that you were using a
DetachedStateManager, but I wanted to have you confirm for me.
The problem is that you are accessing an unloaded field while this Entity
is detached. I agree with you that we shouldn't be throwing an NPE... but
if we were to fix this NPE, OpenJPA would still have to ignore your
change[1]. I think your best best is to load the lazy collection prior to
streaming to the client. Another property you might want to look at is
openjpa.DetachState(AccessUnloaded=false). This property will throw an
exception when/if you try to access a field that isn't loaded.
Thanks,
Rick
[1] [JSR-317 Final Release - pg 81] "The persistence provider must not
merge fields marked LAZY that have not been fetched: it must ignore such
fields when merging."
[2]
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_detach_state
On Mon, Nov 14, 2011 at 3:33 AM, M. Walter <ma...@sbb.ch> wrote:
> Hi Rick,
>
> sorry I wasn't right. The two entities are NOT being created at the client
> side but they are read from the server via RMI. Then the add() method of
> one
> of them is called in order to create a new ManyToMany relationship between
> these two entities. The add() method then calls the other entities' add()
> method and the NPE is raised (I showed you the line the exception occurs).
>
> We casted the entity to PersistenceCapable as you requested.
> In our JUnit integration test a
> com.ibm.ws.persistence.kernel.WsJpaStateManagerImpl state manager is used
> (this works).
> In our RCP client a org.apache.openjpa.kernel.DetachedStateManager state
> manager is used (this fails).
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Strange-behaviour-on-ManyToMany-relationship-using-RCP-client-tp6985422p6991859.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
--
*Rick Curtis*
Re: Strange behaviour on ManyToMany relationship using RCP client
Posted by "M. Walter" <ma...@sbb.ch>.
Hi Rick,
sorry I wasn't right. The two entities are NOT being created at the client
side but they are read from the server via RMI. Then the add() method of one
of them is called in order to create a new ManyToMany relationship between
these two entities. The add() method then calls the other entities' add()
method and the NPE is raised (I showed you the line the exception occurs).
We casted the entity to PersistenceCapable as you requested.
In our JUnit integration test a
com.ibm.ws.persistence.kernel.WsJpaStateManagerImpl state manager is used
(this works).
In our RCP client a org.apache.openjpa.kernel.DetachedStateManager state
manager is used (this fails).
--
View this message in context: http://openjpa.208410.n2.nabble.com/Strange-behaviour-on-ManyToMany-relationship-using-RCP-client-tp6985422p6991859.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Strange behaviour on ManyToMany relationship using RCP client
Posted by Rick Curtis <cu...@gmail.com>.
> because both entities are created at client side and sent to the server
for persisting later.
Just to be clear, in the RCP case, the Entities in question are newly
created and the OpenJPA runtime hasn't ever touched them?
Prior to getting the NPE, can you add some debug and check for a
StateManager? You can check this by casting your Entity to
org.apache.openjpa.enhance.PersistenceCapable and calling
pcGetStateManager().
Thanks,
Rick
On Fri, Nov 11, 2011 at 9:41 AM, M. Walter <ma...@sbb.ch> wrote:
> Well no, because both entities are created at client side and sent to the
> server for persisting later.
>
> Just for this case we implemented a JUnit test and an integration test
> which
> runs against our WebSphere development server and everything works fine.
> But
> as soon as the RCP client comes into play, we get the exception. It's
> weird,
> isn't it?
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Strange-behaviour-on-ManyToMany-relationship-using-RCP-client-tp6985422p6985766.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
--
*Rick Curtis*
Re: Strange behaviour on ManyToMany relationship using RCP client
Posted by "M. Walter" <ma...@sbb.ch>.
Well no, because both entities are created at client side and sent to the
server for persisting later.
Just for this case we implemented a JUnit test and an integration test which
runs against our WebSphere development server and everything works fine. But
as soon as the RCP client comes into play, we get the exception. It's weird,
isn't it?
--
View this message in context: http://openjpa.208410.n2.nabble.com/Strange-behaviour-on-ManyToMany-relationship-using-RCP-client-tp6985422p6985766.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Strange behaviour on ManyToMany relationship using RCP client
Posted by Rick Curtis <cu...@gmail.com>.
Can you try accessing the field metaBpList before sending the Entity to the
client?
Thanks,
Rick
On Fri, Nov 11, 2011 at 8:32 AM, M. Walter <ma...@sbb.ch> wrote:
> Hi Rick,
>
> detach state property configuration is:
> <property name="openjpa.DetachState"
> value="fetch-groups(DetachedStateField=true)" />
>
> We need this because we would like to delete values of fields (set them to
> null in the database explicitly).
>
> Here's the stack trace:
>
> java.lang.NullPointerException
> at xx.xxx.xxxxx.common.entity.stammdaten.Bp.addMetaBp(Bp.java:804)
> at xx.xxx.xxxxx.common.entity.stammdaten.MetaBp.addBp(MetaBp.java:145)
> at
>
> xx.xxx.xxxxx.rcp.stammdaten.internal.ui.editors.metabp.MetaBpEditor$1.run(MetaBpEditor.java:209)
> at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
> at
>
> org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
> at
>
> org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
> at
>
> org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
> at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
> at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
> at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
> at
>
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
> at
>
> xx.xxx.xxxxx.rcp.internal.ui.application.Application.start(Application.java:56)
> at
>
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
> at
>
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
> at
>
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
> at
>
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
> at
>
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
> at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
> at java.lang.reflect.Method.invoke(Method.java:600)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1384)
>
>
> And here's the requested file:
> http://openjpa.208410.n2.nabble.com/file/n6985542/Bp.class Bp.class
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Strange-behaviour-on-ManyToMany-relationship-using-RCP-client-tp6985422p6985542.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
--
*Rick Curtis*
Re: Strange behaviour on ManyToMany relationship using RCP client
Posted by "M. Walter" <ma...@sbb.ch>.
Hi Rick,
detach state property configuration is:
<property name="openjpa.DetachState"
value="fetch-groups(DetachedStateField=true)" />
We need this because we would like to delete values of fields (set them to
null in the database explicitly).
Here's the stack trace:
java.lang.NullPointerException
at xx.xxx.xxxxx.common.entity.stammdaten.Bp.addMetaBp(Bp.java:804)
at xx.xxx.xxxxx.common.entity.stammdaten.MetaBp.addBp(MetaBp.java:145)
at
xx.xxx.xxxxx.rcp.stammdaten.internal.ui.editors.metabp.MetaBpEditor$1.run(MetaBpEditor.java:209)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at
org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at
org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at
xx.xxx.xxxxx.rcp.internal.ui.application.Application.start(Application.java:56)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
at org.eclipse.equinox.launcher.Main.main(Main.java:1384)
And here's the requested file:
http://openjpa.208410.n2.nabble.com/file/n6985542/Bp.class Bp.class
--
View this message in context: http://openjpa.208410.n2.nabble.com/Strange-behaviour-on-ManyToMany-relationship-using-RCP-client-tp6985422p6985542.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Strange behaviour on ManyToMany relationship using RCP client
Posted by Rick Curtis <cu...@gmail.com>.
What do you have openjpa.DetachState set to? Also, can you post the entire
stacktrace? Could you post the enhanced Entity that you're getting the NPE
in?
Thanks,
RIck
On Fri, Nov 11, 2011 at 7:52 AM, M. Walter <ma...@sbb.ch> wrote:
> In our (RCP) client/server application a JAR is packaged on both sides
> containing all build time enhanced entities.
> Now we have a ManyToMany relationship with a join table defined. When we
> add
> both entities to each other to create a new relationship between two
> entities a und b everything works fine on the server side.
> But on the client side we get a very strange NullPointerException at a
> position we thought a NPE is not possible. Please have a look at our code:
>
> Entitiy A:
> public void addB(final B b) {
> if (bList == null) {
> bList = new ArrayList<B>();
> }
> if (!bList.contains(b)) {
> bList.add(b);
> b.addA(this);
> }
> }
>
> Entity B:
> public void addA(final A a) {
> if (aList == null) {
> aList = new ArrayList<A>(); // this code is executed but aList
> is not initialized. Why?
> }
> if (!aList.contains(a)) { // NullPointerException here!! aList is null!
> aList.add(a);
> a.addBp(this);
> }
> }
>
> Does anyone have a hint why this is happening (and on client side only)?
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Strange-behaviour-on-ManyToMany-relationship-using-RCP-client-tp6985422p6985422.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
--
*Rick Curtis*