You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@isis.apache.org by Iain Flynn <fl...@cs.man.ac.uk> on 2011/06/14 17:58:44 UTC
Trouble with relationships - "Object already persisted"
Hi, so I've started using Isis for my MSc project. I'm currently writing a simple application, but I've hit a rather large snag.
I have a couple of classes that have a containment relationship with other classes. I use a reference to the contained object and only allow instances of the contained to be created by the container - this works fine.
However, if I have a class that refers to another domain class that can be created independently, I get an 'object already persisted' error. I can't see what is different about the two cases - I have a newWhatever method implemented in their repositories, where they are persisted (I haven't set up a bi-directional relationship) using the persist() method.
I get the feeling that I'm missing something very simple here, and any help would be greatly appreciated.
Thank you for reading,
- Iain.
Re: Trouble with relationships - "Object already persisted"
Posted by Iain Flynn <fl...@cs.man.ac.uk>.
Thank you very much, persistIfNotAlready did the trick :)
- Iain
On 14 Jun 2011, at 17:56, dan haywood wrote:
> Hi Iain,
> I might be misunderstanding you, but it sounds like you have a graph of
> transient objects. If a transient object is persisted, then it will
> automatically walk the graph and persist all other objects - "persistence by
> reachability". This might be the reason why your other transient object is
> then encountering the "already persisted" error when it in turn attempts to
> persist itself.
>
> Or... maybe you just need to use the
> DomainObjectContainer#persistIfNotAlready(Object) rather than
> DomainObjectContainer#persist(Object).
>
> If neither of these suggestions help, could you post some code here and
> we'll try to help out.
>
> Thx
> Dan
Re: Trouble with relationships - "Object already persisted"
Posted by dan haywood <da...@haywood-associates.co.uk>.
Hi Iain,
I might be misunderstanding you, but it sounds like you have a graph of
transient objects. If a transient object is persisted, then it will
automatically walk the graph and persist all other objects - "persistence by
reachability". This might be the reason why your other transient object is
then encountering the "already persisted" error when it in turn attempts to
persist itself.
Or... maybe you just need to use the
DomainObjectContainer#persistIfNotAlready(Object) rather than
DomainObjectContainer#persist(Object).
If neither of these suggestions help, could you post some code here and
we'll try to help out.
Thx
Dan
On 14 June 2011 16:58, Iain Flynn <fl...@cs.man.ac.uk> wrote:
> Hi, so I've started using Isis for my MSc project. I'm currently writing a
> simple application, but I've hit a rather large snag.
>
> I have a couple of classes that have a containment relationship with other
> classes. I use a reference to the contained object and only allow instances
> of the contained to be created by the container - this works fine.
>
> However, if I have a class that refers to another domain class that can be
> created independently, I get an 'object already persisted' error. I can't
> see what is different about the two cases - I have a newWhatever method
> implemented in their repositories, where they are persisted (I haven't set
> up a bi-directional relationship) using the persist() method.
>
> I get the feeling that I'm missing something very simple here, and any help
> would be greatly appreciated.
>
> Thank you for reading,
>
> - Iain.