Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo]dynamic table-name depending on attribute(saving an eclass to a table with its name = eclass.attribute)
[Teneo]dynamic table-name depending on attribute [message #1016751] Thu, 07 March 2013 15:04 Go to next message
Thomas Steinbach is currently offline Thomas Steinbach
Messages: 13
Registered: March 2013
Junior Member
Hi,

neither my books, nor google could solve the following problem:

An EClass 'MyMetaClass' with the attribute named 'classname' should be mapped to the database, but the tablename should not be 'MyMetaClass' as it is with the default-mapping. The table-name should be the value of 'classname'.

Example:

EClass 'MyMetaClass' with MyMetaClass.classname = 'Cat'
1) defaultmapping: the table-name is 'MyMetaClass'
2) desired mapping: the table-name is 'Cat'

Can you please help me with this? I got stucked for several days Sad
Thanks a lot, Thomas

[Updated on: Thu, 07 March 2013 18:18]

Report message to a moderator

Re: [Teneo]dynamic table-name depending on attribute [message #1016949 is a reply to message #1016751] Fri, 08 March 2013 10:07 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5334
Registered: July 2009
Senior Member
Hi Thomas,
Is there a sub-eclass for Cat also? Or how is the Cat table created?

To get this done the mapping would need to contain a mapping for the Cat type also. If the mapping has this then it is
doable (by giving hibernate the entity name to use when persisting the object).

gr. Martin

On 03/07/2013 06:01 PM, Thomas Steinbach wrote:
> Hi,
>
> neither my books, nor google could solve the following problem:
>
> An EClass 'MyMetaClass' with the attribute named 'classname' should be mapped to the database, but the tablename should
> not be 'MyMetaClass' as it is with the default-mapping. The table-name should be the value of 'classname'.
>
> Example:
>
> EClass 'MyMetaClass' with MyMetaClass.classname = 'Cat'
> 1) defaultmapping: the table-name is 'MyMetaClass'
> 2) desired mapping: the table-name is 'Cat'
>
> Can you please help me with this? I got stucked for several days :(
> Thanks a lot, 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
more precisely description [message #1016996 is a reply to message #1016949] Fri, 08 March 2013 14:18 Go to previous messageGo to next message
Thomas Steinbach is currently offline Thomas Steinbach
Messages: 13
Registered: March 2013
Junior Member
Hi Martin,

I'm so thankful for your help and try to give a more detailed description of the problem below.

>Is there a sub-eclass for Cat also?
The EClass 'MyMetaClass' is used as an equivalent for a java-class or an EClass. So it can have subclasses. This are also modelled with MyMetaClass, with MyMetaClass.name as the name of the subclass and MyMetaClass.superClasses holding the extended classes.

Why do I need this, and don't just take EMF?
1) Because the final model isn't known yet, the application doesn't use EMF-Classes directly to model for example 'Cat's and 'Dog's, but uses meta-elements instead such as the MetaClass, MetaAttribute, etc.
2) The second is mainly that I need more complex description for references(MetaRef) between the classes and need full modelling of MetaOperations inside the editor as described in the IBM-article ECoreX, linked below.

What about Dynamic EMF?
I've already studied your article about Dynamic EMF (and I can say, I was impressed).

So Dynamic EMF could be the solution, but I would need an extension as described in this IBM-article: EcoreX, so a combination of both articles would be a solution. But the problem is I couldn't persist the extended ECoreX-elements and due to complexity of all the involved elements in EMF, Teneo, Hibernate I don't have even an idea where to start with persisting the extended and new created EcoreX-elements.


Back to the mapping:
A first solution would be to tell teneo/hibernate:
When you see an EClass 'MyMetaClass' don't map it to the table MyMetaClass, but map it to a table with name = MyMetaClass.classname
Otherwise apples and oranges would get mixed in only 1 table MyMetaClass.
This can be summarized in a diagram, showing the problem for mapping the MetaAttributes-map too (next step, after solving this step)

With Regards, Thomas

The links:
1) wiki.eclipse.org/Teneo/Hibernate/Dynamic_EMF_Tutorial
2) www.ibm.com/developerworks/library/os-eclipse-emfmetamodel/index.html
3) www.imgbox.de/users/public/images/15FItNgHaB.jpg

[Updated on: Fri, 08 March 2013 14:25]

Report message to a moderator

Re: more precisely description [message #1017092 is a reply to message #1016996] Sat, 09 March 2013 00:03 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5334
Registered: July 2009
Senior Member
Hi Thomas,
I am slowly getting to understand what you mean, so instead of the ecore model itself (EPackage and EClass) you define
your model using a so-called MyMetaClass. Correct?
How are instances of this model done, how is Cat or a Dog instance implemented?

Do you want to persist the model itself (so MyMetaClass with name='cat') or instances (the Cats)?
(I guess the latter)

gr. Martin

On 03/08/2013 03:18 PM, Thomas Steinbach wrote:
> Hi Martin,
>
> I'm so thankful for your help and try to give a more detailed description of the problem below.
>
>> Is there a sub-eclass for Cat also?
> The EClass 'MyMetaClass' is used as an equivalent for a java-class or an EClass. So it can have subclasses. This are
> also modelled with MyMetaClass, with MyMetaClass.name as the name of the subclass and MyMetaClass.superClasses holding
> the extended classes.
>
> Why do I need this, and don't just take EMF?
> 1) Because the final model isn't known yet, the application doesn't use EMF-Classes directly to model for example 'Cat's
> and 'Dog's, but uses meta-elements instead such as the MetaClass, MetaAttribute, etc.
> 2) The second is mainly that I need more complex description for references(MetaRef) between the classes and need full
> modelling of MetaOperations inside the editor as described in the IBM-article ECoreX, linked below.
>
> What about Dynamic EMF?
> I've already studied your http://wiki.eclipse.org/Teneo/Hibernate/Dynamic_EMF_Tutorial about Dynamic EMF (and I can say,
> I was impressed).
>
> So Dynamic EMF could be the solution, but I would need an extension as described in this IBM-article: EcoreX (see link 1
> at the end), so a combination of both articles would be a solution. But the problem is I couldn't persist the extended
> ECoreX-elements and due to complexity of all the involved elements in EMF, Teneo, Hibernate I don't have even an idea
> where to start with persisting the extended and new created EcoreX-elements.
>
>
> Back to the mapping:
> A first solution would be to tell teneo/hibernate:
> When you see an EClass 'MyMetaClass' don't map it to the table MyMetaClass, but map it to a table with name =
> MyMetaClass.classname
> Otherwise apples and oranges would get mixed in only 1 table MyMetaClass.
> This can be summarized in a diagram (see link 2), showing the problem for mapping the MetaAttributes-map too (next step,
> after solving this step)
>
> With Regards, Thomas
>
> The links: 1) www.ibm.com/developerworks/library/os-eclipse-emfmetamodel/index.html
> 2) www.imgbox.de/users/public/images/15FItNgHaB.jpg


--

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
description of the MetaClasses and the instances [message #1017302 is a reply to message #1017092] Mon, 11 March 2013 14:37 Go to previous messageGo to next message
Thomas Steinbach is currently offline Thomas Steinbach
Messages: 13
Registered: March 2013
Junior Member
Hi Martin,

I see how difficult it is to give a detailed description without overwhelming with information, but I think this post will be a good try step by step.


> so instead of the ecore model itself (EPackage and EClass) you define
> your model using a so-called MyMetaClass. Correct?

Correct, this is one of the options I see.
An alternative would be to extend the Ecore itself.
The main reason why I need this is because
- I need extended connection-definition between two 'Nodes' where the definition is in a more mathematical way and can have additional attributes
- I need full modeling of Operations (with parameters and body etc.) in only one editor, with EMF you can create only the stub and then implement it (all in different editors)

How are instances of this model done, how is Cat or a Dog instance implemented?
An instance is realised with an EClass 'MetaObject'.
As an example I pick out how relations between Objects are realised (attributes and operations will be analog I think).
For holding the relations, a MetaObject has a map.
The key for this map is a RelationDefinition, which is saved in the corresponding MetaClass for the MetaObject.
In such a RelationDefinition you can model the name of the relation, the possible min and max values, etc.
The value for this map would be the 'connected' MetaObject or a list with MetaObjects, depending on the multiplicity stored in the RelationDefinition.

Example: modeling the Cat named 'Molly'
This would have a MetaClass:
with MetaClass.name = 'Cat' (not Molly)
the List MetaClass.attributeDefinitions would have an AttributeDefinition ADef1 with name = 'name', type = 'String', min and max = 1

The MetaObject would have:
- (the java attribute) metaClass referencing the Java instance of the corresponding MetaClass
- map-entry with key = ADef1 (the AttributeDefinition above) and a MetaAttribute as the map-value. Now this MetaAttribute would store 'Molly' as the value to model the name of the cat

Do you want to persist the model itself (so MyMetaClass with name='cat') or instances (the Cats)?
Both, the MetaClasses and the instances (MetaObjects).
In contrast to a usual java program the classes and instances should not be separated in different levels (compiletime, runtime), so you can model extended relations between an instance and his or even another class.

This will result in a slightly slower performance than using java-objects, but this will not be a problem, since modeling all in one editor, having the described relations between classes and instances are more important.

summing up
- all this MetaClass, MetaObject, etc. stuff would mimic a lot of the Dynamic EMF descirbed in your article and is only an alternative because I don't know how you can persist elements which are extending the Ecore metamodel, described in this IBM-article.

- the mapping has 2 challenges:
1. tell teneo/hibernate to map an EClass 'MetaObject' not to the table 'MetaObject' but to a table with name = MetaObject.getMetaClass().getClassName();
I got there a bit confused in the other postings with all the meta- and meta-meta-levels, so the classes itself can be mapped to only one table MetaClasses, but the MetaObjects should not
2. the second problem will be the mapping of the particular maps of the EClass 'MetaObject', for example the map holding the attributes or references. Because when the reference has a 1 multiplicity it should be mapped to a column in the appropriate table (for example a cat has only 1 favorite toy to play with), and references with bigger multiplicites than 1 sould be mapped to another table (for example 'cats_photos'.

with best greetings, thomas

[Updated on: Tue, 12 March 2013 14:02]

Report message to a moderator

Re: description of the MetaClasses and the instances [message #1018435 is a reply to message #1017302] Wed, 13 March 2013 20:48 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5334
Registered: July 2009
Senior Member
Hi Thomas,
It is clearer for me now but I think this can only be done by extending Teneo in various ways. It is quite do-able to
add support for this in Teneo. See for example the EAV schema support by Teneo for an alternative way how Teneo persists
data. But as it is a fair amount of work so can only be done as a sponsored development...

gr. Martin

On 03/11/2013 03:37 PM, Thomas Steinbach wrote:
> Hi Martin,
>
> I see how difficult it is to give a detailed description without overwhelming with information, but I think this post
> will be a good try step by step.
>
>
>> so instead of the ecore model itself (EPackage and EClass) you define
>> your model using a so-called MyMetaClass. Correct?
> Correct, this is one of the options I see.
> An alternative would be to extend the Ecore itself.
> The main reason why I need this is because
> - I need extended connection-definition between two 'Nodes' where the definition is in a more mathematical way and can
> have additional attributes
> - I need full modeling of Operations (with parameters and body etc.) in only one editor, with EMF you can create only
> the stub and then implement it (all in different editors)
>
> How are instances of this model done, how is Cat or a Dog instance implemented?
> An instance is realised with an EClass 'MetaObject'.
> As an example I pick out how relations between Objects are realised (attributes and operations will be analog I think).
> For holding the relations, a MetaObject has a map.
> The key for this map is a RelationDefinition, which is saved in the corresponding MetaClass for the MetaObject.
> In such a RelationDefinition you can model the name of the relation, the possible min and max values, etc.
> The value for this map would be the 'connected' MetaObject or a list with MetaObjects, depending on the multiplicity
> stored in the RelationDefinition.
>
> Example: modeling the Cat named 'Molly'
> This would have a MetaClass: with MetaClass.name = 'Cat' (not Molly)
> the List MetaClass.attributeDefinitions would have an AttributeDefinition ADef1 with name = 'name', type = 'String', min
> and max = 1
>
> The MetaObject would have:
> - (the java attribute) metaClass referencing the Java instance of the corresponding MetaClass
> - map-entry with key = ADef1 (the AttributeDefinition above) and a MetaAttribute as the map-value. Now this
> MetaAttribute would store 'Molly' as the value to model the name of the cat
>
> Do you want to persist the model itself (so MyMetaClass with name='cat') or instances (the Cats)?
> Both, the MetaClasses and the instances (MetaObjects).
> In contrast to a usual java program the classes and instances should not be separated in different levels (compiletime,
> runtime), so you can model extended relations between an instance and his or even another class.
>
> This will result in a slightly slower performance than using java-objects, but this will not be a problem, since
> modeling all in one editor, having the described relations between classes and instances are more important.
>
> summing up
> - all this MetaClass, MetaObject, etc. stuff would mimic a lot of the Dynamic EMF descirbed in your
> wiki.eclipse.org/Teneo/Hibernate/Dynamic_EMF_Tutorial and is only an alternative because I don't know how you can
> persist elements which are extending the Ecore metamodel, described in this
> http://www.ibm.com/developerworks/library/os-eclipse-emfmetamodel/index.html.
>
> - the mapping has 2 challenges:
> 1. tell teneo/hibernate to map an EClass 'MetaClass' not to the table 'MetaClass' but to a table named as the
> attribute-value MetaClass.name; so a modeled Class 'Cat' would not be mapped to the table 'MetaClasses' (having cats,
> dogs, etc. all in one table), but mapped to the table 'Cats'.
> 2. the second problem will be the mapping of the particular maps of the EClass 'MetaObject', for example the map holding
> the attributes or references. Because when the reference has a 1 multiplicity it should be mapped to a column in the
> appropriate table (for example a cat has only 1 favorite toy to play with), and references with bigger multiplicites
> than 1 sould be mapped to another table (for example 'cats_photos'.
>


--

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
Custom EntityPersister [message #1020570 is a reply to message #1018435] Mon, 18 March 2013 13:37 Go to previous messageGo to next message
Thomas Steinbach is currently offline Thomas Steinbach
Messages: 13
Registered: March 2013
Junior Member
Martin, thanks a lot for your help.

A sponsored development would not be a problem in general. But I worry that it will exceed my contingency. Maybe there are any comparable cases to get an idea of how much time and money it would need?

Custom EntityPersister
Based on further readings since my posts, I have the hope to get it done with a custom EntityPersister. Maybe you searched this a couple of years ago forum.hibernate.org/viewtopic.php?p=2420662 and maybe you got it solved.

The problem with this way and teneo is that I can't specify a custom EntityPersister. Nor with annotations neither with a mapping xml-file. Even it's not possible to use the teneo extension-manager to specify it.

With best regards,
Thomas
Re: Custom EntityPersister [message #1020580 is a reply to message #1020570] Mon, 18 March 2013 13:51 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5334
Registered: July 2009
Senior Member
Hi Thomas,
I think you can set a provider of entity persisters on the configuration object:
http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#d5e1591

You can get the configuration object from the datastore, set the persister class provider before initializing the datastore.

gr. Martin

On 03/18/2013 02:37 PM, Thomas Steinbach wrote:
> Martin, thanks a lot for your help.
>
> A sponsored development would not be a problem in general. But I worry that it will exceed my contingency. Maybe there
> are any comparable cases to get an idea of how much time and money it would need?
>
> Custom EntityPersister
> Based on further readings since my posts, I have the hope to get it done with a custom EntityPersister. Maybe you
> searched this a couple of years ago forum.hibernate.org/viewtopic.php?p=2420662 and maybe you got it solved.
>
> The problem with this way and teneo is that I can't specify a custom EntityPersister. Nor with annotations neither with
> a mapping xml-file. Even it's not possible to use the teneo http://wiki.eclipse.org/Teneo/Hibernate/Extensions to
> specify it.
>
> 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: Custom EntityPersister [message #1020588 is a reply to message #1020570] Mon, 18 March 2013 14:14 Go to previous message
Martin Taal is currently offline Martin Taal
Messages: 5334
Registered: July 2009
Senior Member
Hi Thomas,
Btw, I can give you an estimate on how much work it is to get this done. Can you send me a private/direct email to mtaal
dot elver.org if you are interested?

gr. Martin

On 03/18/2013 02:37 PM, Thomas Steinbach wrote:
> Martin, thanks a lot for your help.
>
> A sponsored development would not be a problem in general. But I worry that it will exceed my contingency. Maybe there
> are any comparable cases to get an idea of how much time and money it would need?
>
> Custom EntityPersister
> Based on further readings since my posts, I have the hope to get it done with a custom EntityPersister. Maybe you
> searched this a couple of years ago forum.hibernate.org/viewtopic.php?p=2420662 and maybe you got it solved.
>
> The problem with this way and teneo is that I can't specify a custom EntityPersister. Nor with annotations neither with
> a mapping xml-file. Even it's not possible to use the teneo http://wiki.eclipse.org/Teneo/Hibernate/Extensions to
> specify it.
>
> 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:[Texo] using Texo + Eclipselink in a J2SE environment
Next Topic:[teneo] Problem with double index on column
Goto Forum:
  


Current Time: Tue Sep 23 14:38:45 GMT 2014

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

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