Shallow save

22 views
Skip to first unread message

Zoran Jeremic

unread,
Apr 20, 2011, 4:26:46 PM4/20/11
to jenabean-dev
Hi,

I've been using a JenaBean for a while in a project I'm working on,
but I'm not an expert in it. I'm using a shallow saving to save the
resource and recently I noticed a strange behavior. At least it was
strange for me. Resource connected with instance I'm saving is also
saved. For example, if I have objectA which is related with objectB,
objectB is connected with objectC, and objectC is connected with
objectD. If I save objectA, objectD is also saved. I thought that this
should happen only if I use deepSave.
Please let me know if this is expected behavior and if so, how can I
make it only objectA and it's properties are saved.

Best,
Zoran

Taylor Cowan

unread,
Apr 20, 2011, 11:25:59 PM4/20/11
to jenabe...@googlegroups.com
Hi Zoran,

I'm happy to hear you are using JenaBean. I don't know how much raw
Jena programming you've done, but I find it to be much more
enjoyable/simple to get information into and out of the graph using
beans.

This is the expected behavior. I remember when implementing this I
struggled with how much to persist. Shallow ignores plural
properties, but goes ahead and saves singular properties with
values...and it's recursive.

this should not be hard to fix...giving it a look.

Taylor

> --
> You received this message because you are subscribed to the Google Groups "jenabean-dev" group.
> To post to this group, send email to jenabe...@googlegroups.com.
> To unsubscribe from this group, send email to jenabean-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jenabean-dev?hl=en.
>
>

Zoran Jeremic

unread,
Apr 21, 2011, 6:04:27 AM4/21/11
to jenabean-dev
Hi Taylor,

> enjoyable/simple to get information into and out of the graph using
> beans.

Yes, I agree with that.

> struggled with how much to persist. Shallow ignores plural
> properties, but goes ahead and saves singular properties with
I'm afraid this is not exactly the same in my case.
I have the following situation:
SocialStream isRelatedTo (plural property) SocialEvent
SocialEvent isRelatedTo (singular property) Event
Event isRelatedTo (singular property) LearningGoal

When I save SocialStream, LearningGoal is also changed. As you can
see, the first connection is plural, so it should not save other
instances.

Best,
Zoran

On Apr 21, 5:25 am, Taylor Cowan <thewebseman...@gmail.com> wrote:
> Hi Zoran,
>
> I'm happy to hear you are using JenaBean.  I don't know how much raw
> Jena programming you've done, but I find it to be much more
> enjoyable/simple to get information into and out of the graph using
> beans.
>
> This is the expected behavior.  I remember when implementing this I
> struggled with how much to persist.  Shallow ignores plural
> properties, but goes ahead and saves singular properties with
> values...and it's recursive.
>
> this should not be hard to fix...giving it a look.
>
> Taylor
>

Zoran Jeremic

unread,
Apr 22, 2011, 1:58:12 PM4/22/11
to jenabean-dev
Is there anybody who has explanation why this is happening?

Thanks,
Zoran

Taylor Cowan

unread,
Apr 22, 2011, 8:28:17 PM4/22/11
to Zoran Jeremic, jenabean-dev
Zoran, please make a simple test case email code and I will tell you
why.

Sent from my Windows Phone From: Zoran Jeremic
Sent: Friday, April 22, 2011 12:58 PM
To: jenabean-dev
Subject: Re: Shallow save

Taylor Cowan

unread,
Apr 22, 2011, 9:29:07 PM4/22/11
to Zoran Jeremic, jenabean-dev
Consider this test case:
http://jenabean.googlecode.com/svn/trunk/jenabean/src/test/java/test/bean/TestLoadWith.java

if you don't access a plural property, they are actually empty. Only
once you've called get<Property> is the data pulled from the graph.

Adding a value is a direction relationship, so save() does add the new
information. I think what's needed is a saveShallow() that only saves
properties, literals, but you can see in many of the test
cases...adding values to a plural property and calling save() modifies
the graph.

Taylor

Taylor Cowan

unread,
Apr 22, 2011, 9:52:02 PM4/22/11
to Zoran Jeremic, jenabean-dev
Zoran,

If you want to make very specific changes to the graph, or retrieve
values, there is also a fluet api for accessing Jena.

See:http://www.thewebsemantic.com/2009/03/10/writing-out-sioc-triples-using-jena-jenabean/

and http://jenabean.googlecode.com/svn/trunk/jenabean/src/test/java/test/thing/TestBasic.java

Zoran Jeremic

unread,
Apr 23, 2011, 3:48:00 PM4/23/11
to jenabean-dev
Hi Taylor,

Thank you for your explanation. Just in order to check if I understood
it well, please let me know if this is correct.
If I load SocialStream and add 1 instance of plural property
SocialEvent to it, saveShallow of SocialStream will also save only
this specific SocialEvent, but if I call getSocialEvents and add 1
instance before I call saveShallow, then all SocialEvents including
new one and the other related to this SocialStream will be saved.
Is that how the things works with shallow save?

Zoran

On Apr 23, 3:52 am, Taylor Cowan <thewebseman...@gmail.com> wrote:
> Zoran,
>
> If you want to make very specific changes to the graph, or retrieve
> values, there is also a fluet api for accessing Jena.
>
> See:http://www.thewebsemantic.com/2009/03/10/writing-out-sioc-triples-usi...
>
> andhttp://jenabean.googlecode.com/svn/trunk/jenabean/src/test/java/test/...
>
> On Fri, Apr 22, 2011 at 8:29 PM, Taylor Cowan <thewebseman...@gmail.com> wrote:
> > Consider this test case:
> >http://jenabean.googlecode.com/svn/trunk/jenabean/src/test/java/test/...
>
> > if you don't access a plural property, they are actually empty.  Only
> > once you've called get<Property>  is the data pulled from the graph.
>
> > Adding a value is a direction relationship, so save() does add the new
> > information.  I think what's needed is a saveShallow() that only saves
> > properties, literals,  but you can see in many of the test
> > cases...adding values to a plural property and calling save() modifies
> > the graph.
>
> > Taylor
>

Nikola Milikic

unread,
Feb 8, 2012, 5:47:08 PM2/8/12
to jenabe...@googlegroups.com
Hi all,

I'm working with Zoran on this project and has been struggling with this issue for a past few days.

The scenario which Zoran described where if you have object of a ClassA which has a collection propAB of objects of a class ClassB, when you add a new instance to that collection and save object of the class ClassA, Jenabean will also save added object of the class ClassB.

Reason for that is that in thewebsemantic.CollectionSaver class, inside its method save() on line 30 there is a call to:

subject.addProperty(property, writer.toRDFNode(obj)); 

which will if obj is not literal, nor URI, nor thesemanticweb.Resource execute _write method (thewebsemantic.Bean2RDF L210). That will, since the object is not inside the cycle save it to the model. And this can propagate to collections of obj and so on. That means that shallow save is not actually shallow. It saves elements of a collection and also fields which are not Collections. 

I think checking whether the object is contained inside the cycle array is not enough. Maybe checking whether a resources is already stored in the model?

But, a more elegant solution to this, I think, would be introducing an annotation where it could be stated that cascading to that resource when saving should be performed. Or this can be an attribute of @RdfProperty annotation. What do you think?


Best,

Nikola

Reply all
Reply to author
Forward
0 new messages