Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » teneo hibernate example(relation between resource and session)
teneo hibernate example [message #1045652] Sat, 20 April 2013 16:31 Go to next message
Thomas Steinbach is currently offline Thomas SteinbachFriend
Messages: 13
Registered: March 2013
Junior Member
Hi,

In the teneo hibernate tutorial two ways for saving and retrieving objects are mixed:
1. session.save(..) and retrieving by a query
2. resource.save(..) and retrieving by resource.getContents.get(0)

My problem is that the object-result retrieved with a query from the session-concept and
the object-result retrieved from resource.getContents.get(0) have the same stored attributes but are different java-object-instances.

I do not understand fully the relation between both concepts, but

1) I want to use the Resource-concept for saving, because otherwise in my GEF-Editor I would have to traverse all executed commands in the command-stack until the last save-marker and do a session.save() on all "touched" elements, for which the Command-class would be needed to get extended, for example command.getChangedElements()
<-- is this the right way? Seems for me complicated

2) But I would need the possibility of queries too.

So my questions are:
Is there a way to merge the object-identities of both concepts?
Maybe I am doing something totaly wrong?
What would be a good way to save objects in a GEF-Editor?
->Because saving particular elements with session.save(xy) is good in a tutorial where you know the few elements, but in an GEF-Editor it would be more complex (see my initial approach above).

With best regards,
Thomas
Re: teneo hibernate example [message #1046340 is a reply to message #1045652] Sun, 21 April 2013 19:43 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Thomas,
The instances are different because the resource internally uses a different session. The Teneo EMF Resource also has
the possibility to be loaded with resources or to share a session:
http://wiki.eclipse.org/Teneo/Hibernate/EMF_Resource

For the rest I don't have experience with rcp's or gef, so I am afraid that I can't help any further with the other
questions... but I hope the above already helps.

gr. Martin


On 04/20/2013 06:31 PM, Thomas Steinbach wrote:
> Hi,
>
> In the http://wiki.eclipse.org/Teneo/Hibernate/Tutorial two ways for saving and retrieving objects are mixed:
> 1. session.save(..) and retrieving by a query
> 2. resource.save(..) and retrieving by resource.getContents.get(0)
>
> My problem is that the object-result retrieved with a query from the session-concept and
> the object-result retrieved from resource.getContents.get(0) have the same stored attributes but are different
> java-object-instances.
>
> I do not understand fully the relation between both concepts, but
>
> 1) I want to use the Resource-concept for saving, because otherwise in my GEF-Editor I would have to traverse all
> executed commands in the command-stack until the last save-marker and do a session.save() on all "touched" elements, for
> which the Command-class would be needed to get extended, for example command.getChangedElements()
> <-- is this the right way? Seems for me complicated
>
> 2) But I would need the possibility of queries too.
>
> So my questions are:
> Is there a way to merge the object-identities of both concepts?
> Maybe I am doing something totaly wrong?
> What would be a good way to save objects in a GEF-Editor?
> ->Because saving particular elements with session.save(xy) is good in a tutorial where you know the few elements, but in
> an GEF-Editor it would be more complex (see my initial approach above).
>
> With best regards,
> Thomas
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: teneo hibernate example [message #1046892 is a reply to message #1046340] Mon, 22 April 2013 14:01 Go to previous messageGo to next message
Thomas Steinbach is currently offline Thomas SteinbachFriend
Messages: 13
Registered: March 2013
Junior Member
Hi Martin,

thank you for this little tip with big help Smile
It works, with a little confusion:

Based on the linked tutorial (see first post) I've first added the dataStoreName as in the code below. No errors etc. at the console, but the results retrieved by session and by resource still weren't the same object, only having the same attributes.
String uriStr = "hibernate://?" + HibernateResource.DS_NAME_PARAM
				+ "=" + dataStoreName + "&" 
				+ HibernateResource.SESSION_CONTROLLER_PARAM + "=" + sessionControllerName;


After some "experiments" I've removed the dataStoreName just to give it a try and it works. But I'm wondering why this was needed for the tutorial and now works without but connecting to the right postgres-DB.
String uriStr = "hibernate://?" 
				+ HibernateResource.SESSION_CONTROLLER_PARAM + "=" + sessionControllerName;



One little question remains:
Do you know how the Resource-concept works in general? I mean,
- does the Resource "climb down" all its content-elements and persist them one by one
- or when you add an object to its container, the object "climbs" up until it reaches a resource and the resource registers itself as a listener
- maybe a combination or even something else

So how does a Resource know which elements are changed and needs to be saved?

With best regards,
Thomas
Re: teneo hibernate example [message #1047712 is a reply to message #1046892] Tue, 23 April 2013 14:52 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Thomas,
It works as it uses the session controller which you specify/have registered, the session controller knows which
datastore to use (you set one in it right?).

The resource keeps track which objects are new and saves these explicitly. Hibernate itself keeps track of which objects
have changed and persists the changes automatically.

When adding a new object to a resource, its children are also automatically added to the resource.
When you add an object to a container, it automatically is also added to the resource holding the containment tree (so
as you indicate below).

gr. Martin

On 04/22/2013 04:01 PM, Thomas Steinbach wrote:
> Hi Martin,
>
> thank you for this little tip with big help :)
> It works, with a little confusion:
>
> Based on the linked tutorial (see first post) I've first added the dataStoreName as in the code below. No errors etc. at
> the console, but the results retrieved by session and by resource still weren't the same object, only having the same
> attributes.
>
> String uriStr = "hibernate://?" + HibernateResource.DS_NAME_PARAM
> + "=" + dataStoreName + "&" + HibernateResource.SESSION_CONTROLLER_PARAM + "=" +
> sessionControllerName;
>
>
> After some "experiments" I've removed the dataStoreName just to give it a try and it works. But I'm wondering why this
> was needed for the tutorial and now works without but connecting to the right postgres-DB.
>
> String uriStr = "hibernate://?" + HibernateResource.SESSION_CONTROLLER_PARAM + "=" + sessionControllerName;
>
>
> One little question remains:
> Do you know how the Resource-concept works in general? I mean, - does the Resource "climb down" all its content-elements
> and persist them one by one
> - or when you add an object to its container, the object "climbs" up until it reaches a resource and the resource
> registers itself as a listener
> - maybe a combination or even something else
>
> So how does a Resource know which elements are changed and needs to be saved?
>
> With best regards,
> Thomas


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:[EMF Facet] How to access model instances?
Next Topic:MWE framework and Check language
Goto Forum:
  


Current Time: Sat Apr 20 02:02:14 GMT 2024

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

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

Back to the top