Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Modify resource set without a write transaction
Modify resource set without a write transaction [message #419052] Fri, 09 May 2008 11:02 Go to next message
J. Rietz is currently offline J. RietzFriend
Messages: 40
Registered: July 2009
Member
Hi,

I have a problem where I get the following exception:
java.lang.IllegalStateException: Cannot modify resource set without a
write transaction

The background is that, for some reasons (which I won't mention here),
implementation is done in a way that when evaluating an EMF getter it
will, for a certain scenario, call a setter. I.e. a feature value will be
changed/set.
If this getter is evaluated during resource save (which it obviously is) I
get the exception.

So, now to my questions.
Is this way of implementation (change/set values through getters) to be
condemned?
Or else, how can I get it work? Should I use some Command
(org.eclipse.emf.edit.command?) to avoid this kind of trouble?


Stack trace:

java.lang.IllegalStateException: Cannot modify resource set without a
write transaction
at
org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ssertWriting(TransactionChangeRecorder.java:332)
at
org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ppendNotification(TransactionChangeRecorder.java:294)
at
org.eclipse.emf.transaction.impl.TransactionChangeRecorder.p rocessObjectNotification(TransactionChangeRecorder.java:276)
at
org.eclipse.emf.transaction.impl.TransactionChangeRecorder.n otifyChanged(TransactionChangeRecorder.java:232)
at
org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
at
com.bombardier.ebitool.data.infrastructure.impl.LegImpl.setI dentity(LegImpl.java:163)
at
com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.sw apEnds(TrackImpl.java:1093)
at
com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.ge tEnds(TrackImpl.java:304)
at
com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.ge tIdentityWithStation(TrackImpl.java:1105)
at
com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.ge tIdentity(TrackImpl.java:273)
at
com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.eG et(TrackImpl.java:597)
at
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1002)
at
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:994)
at
org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getValue(XMLHel perImpl.java:307)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeSingl e(XMLSaveImpl.java:1608)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1196)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XML SaveImpl.java:2590)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1105)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:986)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedMany (XMLSaveImpl.java:2291)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1464)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XML SaveImpl.java:2590)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:653)
at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:581)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:253)
at
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
...
...


Regards,
Joachim
Re: Modify resource set without a write transaction [message #419054 is a reply to message #419052] Fri, 09 May 2008 12:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Joachim,

Generally having what's expected to be read only access producing side
effects on the model is a bad idea, especially when using the
transaction framework, because it's fastidious about ensuring that
writes only happen in an exclusive write transaction. You could do the
save as part of a write transaction, but if at all possible, it's best
to avoid this; of course it's possible to disable notification,
eSetDelivery(false), but that might cause problems in terms of undo
working properly.


Joachim Rietz wrote:
> Hi,
>
> I have a problem where I get the following exception:
> java.lang.IllegalStateException: Cannot modify resource set without a
> write transaction
>
> The background is that, for some reasons (which I won't mention here),
> implementation is done in a way that when evaluating an EMF getter it
> will, for a certain scenario, call a setter. I.e. a feature value will
> be changed/set.
> If this getter is evaluated during resource save (which it obviously
> is) I get the exception.
>
> So, now to my questions.
> Is this way of implementation (change/set values through getters) to
> be condemned?
> Or else, how can I get it work? Should I use some Command
> (org.eclipse.emf.edit.command?) to avoid this kind of trouble?
>
>
> Stack trace:
>
> java.lang.IllegalStateException: Cannot modify resource set without a
> write transaction
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ssertWriting(TransactionChangeRecorder.java:332)
>
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ppendNotification(TransactionChangeRecorder.java:294)
>
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.p rocessObjectNotification(TransactionChangeRecorder.java:276)
>
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.n otifyChanged(TransactionChangeRecorder.java:232)
>
> at
> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.LegImpl.setI dentity(LegImpl.java:163)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.sw apEnds(TrackImpl.java:1093)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.ge tEnds(TrackImpl.java:304)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.ge tIdentityWithStation(TrackImpl.java:1105)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.ge tIdentity(TrackImpl.java:273)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.eG et(TrackImpl.java:597)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1002)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:994)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getValue(XMLHel perImpl.java:307)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeSingl e(XMLSaveImpl.java:1608)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1196)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XML SaveImpl.java:2590)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1105)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:986)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedMany (XMLSaveImpl.java:2291)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1464)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XML SaveImpl.java:2590)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:653)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:581)
> at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:253)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>
> ...
> ...
>
>
> Regards,
> Joachim
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Modify resource set without a write transaction [message #419055 is a reply to message #419052] Fri, 09 May 2008 13:13 Go to previous message
Eclipse UserFriend
Originally posted by: give.a.damus.gmail.com

Hi, Joachim,

In general, it will be surprising for clients to find that observing the
state of a model will change it (think Heisenberg). If this property is
intended to be lazily initialized, then it would be reasonable to set it
without notification as Ed suggests (perhaps by not using the setter
method, because disabling notifications is an object-wide state which
will suppress RESOLVE notifications for proxies). In the case of lazy
initialization, the property has necessarily never been observed before,
so nobody will miss the notification that it has changed.

HTH,

Christian


Joachim Rietz wrote:
> Hi,
>
> I have a problem where I get the following exception:
> java.lang.IllegalStateException: Cannot modify resource set without a
> write transaction
>
> The background is that, for some reasons (which I won't mention here),
> implementation is done in a way that when evaluating an EMF getter it
> will, for a certain scenario, call a setter. I.e. a feature value will
> be changed/set.
> If this getter is evaluated during resource save (which it obviously is)
> I get the exception.
>
> So, now to my questions.
> Is this way of implementation (change/set values through getters) to be
> condemned?
> Or else, how can I get it work? Should I use some Command
> (org.eclipse.emf.edit.command?) to avoid this kind of trouble?
>
>
> Stack trace:
>
> java.lang.IllegalStateException: Cannot modify resource set without a
> write transaction
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ssertWriting(TransactionChangeRecorder.java:332)
>
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ppendNotification(TransactionChangeRecorder.java:294)
>
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.p rocessObjectNotification(TransactionChangeRecorder.java:276)
>
> at
> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.n otifyChanged(TransactionChangeRecorder.java:232)
>
> at
> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.LegImpl.setI dentity(LegImpl.java:163)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.sw apEnds(TrackImpl.java:1093)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.ge tEnds(TrackImpl.java:304)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.ge tIdentityWithStation(TrackImpl.java:1105)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.ge tIdentity(TrackImpl.java:273)
>
> at
> com.bombardier.ebitool.data.infrastructure.impl.TrackImpl.eG et(TrackImpl.java:597)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1002)
>
> at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:994)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getValue(XMLHel perImpl.java:307)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveDataTypeSingl e(XMLSaveImpl.java:1608)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1196)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XML SaveImpl.java:2590)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:1105)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSa veImpl.java:986)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedMany (XMLSaveImpl.java:2291)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLS aveImpl.java:1464)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XML SaveImpl.java:2590)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XM LSaveImpl.java:653)
>
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveI mpl.java:581)
> at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:253)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:205)
>
> ..
> ..
>
>
> Regards,
> Joachim
>
Previous Topic:[Validation] Markers missing Location
Next Topic:Creating multiple children
Goto Forum:
  


Current Time: Fri Apr 19 04:19:34 GMT 2024

Powered by FUDForum. Page generated in 0.01718 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top