Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Query by Class question and potential problem
Query by Class question and potential problem [message #75386] Wed, 14 March 2007 01:48 Go to next message
Jean-Denis Boudreault is currently offline Jean-Denis BoudreaultFriend
Messages: 55
Registered: July 2009
Member
Hello,


i am currently porting my old POJO/hibernate code to
EMF/Teneo/Hibernate. for many queries, i used to query by "load" or
"get" and specifying the class name.

i.e.: List myObjects =
this.getHibernateTemplate().loadAll(MyObjectImpl.class);

what happens is an exception saying that the object MyObject is not
defined.

<exception>Caused by: org.hibernate.MappingException: Unknown entity:
com.something.model.impl.MyObjectImpl</exception>

Since this code used to work before teneo, i realized that it was due to
the interface / implementation of EMF.


Basically, if it is in the package "pack1.pack2", the it will create an
interface at:

pack1.pack2.MyObject

and it will create an implementation at:

pack1.pack2.impl.MyObjectImpl.


Teneo gives the interface name to the mapped entity in the hbm.xml file
(i.e. entity-name="MyObject"), and this seems to cause problems when
invoking by class type. If i provide the interface name, then it wont
work since hibernate expects the implementation. but if i use the
implementation, the name does not match the mapped entity.

If i query by string class name (or by query), all works fine. (as
expressed in the examples on the elver site)

my question is: is there a way to query by class type in teneo, or must
we explicitly provide the type by string name? perhaps can we force the
entity name in the hbm file to be the implementation one? and is this a
known limitation or am i missing something?

thanks a lot for your invaluable help!
Re: Query by Class question and potential problem [message #75403 is a reply to message #75386] Wed, 14 March 2007 05:08 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Jean-Denis,
Teneo (the hbm file) uses the EClass names instead of the interface/class names and the efeature
names instead of the java member/property names. This makes it possible to support dynamic emf.
The hibernate api normally has an equivalent string (entityname) version of each method to support this.

If required, after initializing the hbdatastore there is this class:
ERuntime.INSTANCE
to easily map from and to eclass/java interface/java implementation classes.

gr. Martin

Jean-Denis Boudreault wrote:
> Hello,
>
>
> i am currently porting my old POJO/hibernate code to
> EMF/Teneo/Hibernate. for many queries, i used to query by "load" or
> "get" and specifying the class name.
>
> i.e.: List myObjects =
> this.getHibernateTemplate().loadAll(MyObjectImpl.class);
>
> what happens is an exception saying that the object MyObject is not
> defined.
>
> <exception>Caused by: org.hibernate.MappingException: Unknown entity:
> com.something.model.impl.MyObjectImpl</exception>
>
> Since this code used to work before teneo, i realized that it was due to
> the interface / implementation of EMF.
>
>
> Basically, if it is in the package "pack1.pack2", the it will create an
> interface at:
>
> pack1.pack2.MyObject
>
> and it will create an implementation at:
>
> pack1.pack2.impl.MyObjectImpl.
>
>
> Teneo gives the interface name to the mapped entity in the hbm.xml file
> (i.e. entity-name="MyObject"), and this seems to cause problems when
> invoking by class type. If i provide the interface name, then it wont
> work since hibernate expects the implementation. but if i use the
> implementation, the name does not match the mapped entity.
>
> If i query by string class name (or by query), all works fine. (as
> expressed in the examples on the elver site)
>
> my question is: is there a way to query by class type in teneo, or must
> we explicitly provide the type by string name? perhaps can we force the
> entity name in the hbm file to be the implementation one? and is this a
> known limitation or am i missing something?
>
> thanks a lot for your invaluable help!


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Query by Class question and potential problem [message #75441 is a reply to message #75403] Wed, 14 March 2007 13:34 Go to previous messageGo to next message
Jean-Denis Boudreault is currently offline Jean-Denis BoudreaultFriend
Messages: 55
Registered: July 2009
Member
Thanks Martin,


well, actualyl thats what i meant by teneo uses the interface name. i know
in fact that it uses the EClass name, but in most cases, it will match the
interface (without the package); but i understand the subtillity.

now, i have a second question, which i almost posted in another thread,
but i will link to this one, since it is somewhat related (due to class
naming / specifying).

I believe that teneo does not support the @Proxy hibernate annotation, is
that correct? if so, is there any particular limitation for this
decision, or could it be implemented rapidly? i ask as if it is not there
yet, i may help to add it.

of course, this would imply of being able to specify fully specified class
names, and to be able to distinguish between the interface and the
implementation. and of course, if we add it for Proxy, could we also add
it for class name and/or entity-name? (or at least have the option to set
it). what do you think about adding @Proxy and potentially being able to
fully classify names in the hbm file?


thanks Martin
Re: Query by Class question and potential problem [message #75457 is a reply to message #75441] Wed, 14 March 2007 14:12 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Jean-Denis,
Yes I thought about allowing Teneo to run in different modes: mapping the model (for dynamic emf)
and mapping the classes (for specific cases where proxying is important). It is not that difficult
to replace the entityname in the mapping with the actual implementation classname. The attribute
name needs to be different in the class tag and the attribute should contain the actual impl classname.
The mapping logic uses the getEntityName method from the MappingContext class which already contains
some logic for getting the impl name. In addition the ERuntime.INSTANCE object can help to get the
interface for a certain eclass (to get the interfacename).

So if you are interested for your situation then please try it out to see if it can be changed to
real impl name and test it with proxying. If it works fine then this can be incorporated as a
separate mode-of-operation in Teneo.

gr. Martin

Jean-Denis Boudreault wrote:
> Thanks Martin,
>
>
> well, actualyl thats what i meant by teneo uses the interface name. i
> know in fact that it uses the EClass name, but in most cases, it will
> match the interface (without the package); but i understand the subtillity.
>
> now, i have a second question, which i almost posted in another thread,
> but i will link to this one, since it is somewhat related (due to class
> naming / specifying).
> I believe that teneo does not support the @Proxy hibernate annotation,
> is that correct? if so, is there any particular limitation for this
> decision, or could it be implemented rapidly? i ask as if it is not
> there yet, i may help to add it.
>
> of course, this would imply of being able to specify fully specified
> class names, and to be able to distinguish between the interface and the
> implementation. and of course, if we add it for Proxy, could we also add
> it for class name and/or entity-name? (or at least have the option to
> set it). what do you think about adding @Proxy and potentially being
> able to fully classify names in the hbm file?
>
>
> thanks Martin
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Query by Class question and potential problem [message #75492 is a reply to message #75457] Wed, 14 March 2007 14:48 Go to previous messageGo to next message
Jean-Denis Boudreault is currently offline Jean-Denis BoudreaultFriend
Messages: 55
Registered: July 2009
Member
ok, thanks. i will do so.


do you have any preferred method to switch naming modes for the class
name? do you wish to use an annotation (im not sure which one would do in
either JPA or hibernate?) or would you prefer some config file option? (a
config file option might make it hard to discriminate which entity should
be fully classified and which one is not, but might be needed if no
annotation can be used).


thanks for helping me define the switch and i will add this feature ASAP.


note: this is just a suggestion, but in the case that no hibernate or JPA
annotation can do, what do you think if we added teneo specific
annotations? They could later be used to specify other teneo specific
settings on entities and fields. just an idea of course.
Re: Query by Class question and potential problem [message #75575 is a reply to message #75492] Wed, 14 March 2007 15:20 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi J-D,
I prefer a global option for this (PersistenceOptions). The system can actually be made 'smarter',
it can detect if there is an implementation class for a eclass. If so it can map it as a real class.
If no impl. class can be found then the entity mapping can be used (the current behavior). This
behavior supports the combination of both dynamic emf and static emf.
As this is new behavior I would prefer a global persistence option which controls this (new or old
behavior). Later this can maybe be made the default.

Thanks!

gr. Martin

JD wrote:
> ok, thanks. i will do so.
>
>
> do you have any preferred method to switch naming modes for the class
> name? do you wish to use an annotation (im not sure which one would do
> in either JPA or hibernate?) or would you prefer some config file
> option? (a config file option might make it hard to discriminate which
> entity should be fully classified and which one is not, but might be
> needed if no annotation can be used).
>
> thanks for helping me define the switch and i will add this feature ASAP.
>
>
> note: this is just a suggestion, but in the case that no hibernate or
> JPA annotation can do, what do you think if we added teneo specific
> annotations? They could later be used to specify other teneo specific
> settings on entities and fields. just an idea of course.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Query by Class question and potential problem [message #75642 is a reply to message #75575] Wed, 14 March 2007 16:46 Go to previous message
Jean-Denis Boudreault is currently offline Jean-Denis BoudreaultFriend
Messages: 55
Registered: July 2009
Member
created feature requests #177369 & #177370.
Re: Query by Class question and potential problem [message #603601 is a reply to message #75386] Wed, 14 March 2007 05:08 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Jean-Denis,
Teneo (the hbm file) uses the EClass names instead of the interface/class names and the efeature
names instead of the java member/property names. This makes it possible to support dynamic emf.
The hibernate api normally has an equivalent string (entityname) version of each method to support this.

If required, after initializing the hbdatastore there is this class:
ERuntime.INSTANCE
to easily map from and to eclass/java interface/java implementation classes.

gr. Martin

Jean-Denis Boudreault wrote:
> Hello,
>
>
> i am currently porting my old POJO/hibernate code to
> EMF/Teneo/Hibernate. for many queries, i used to query by "load" or
> "get" and specifying the class name.
>
> i.e.: List myObjects =
> this.getHibernateTemplate().loadAll(MyObjectImpl.class);
>
> what happens is an exception saying that the object MyObject is not
> defined.
>
> <exception>Caused by: org.hibernate.MappingException: Unknown entity:
> com.something.model.impl.MyObjectImpl</exception>
>
> Since this code used to work before teneo, i realized that it was due to
> the interface / implementation of EMF.
>
>
> Basically, if it is in the package "pack1.pack2", the it will create an
> interface at:
>
> pack1.pack2.MyObject
>
> and it will create an implementation at:
>
> pack1.pack2.impl.MyObjectImpl.
>
>
> Teneo gives the interface name to the mapped entity in the hbm.xml file
> (i.e. entity-name="MyObject"), and this seems to cause problems when
> invoking by class type. If i provide the interface name, then it wont
> work since hibernate expects the implementation. but if i use the
> implementation, the name does not match the mapped entity.
>
> If i query by string class name (or by query), all works fine. (as
> expressed in the examples on the elver site)
>
> my question is: is there a way to query by class type in teneo, or must
> we explicitly provide the type by string name? perhaps can we force the
> entity name in the hbm file to be the implementation one? and is this a
> known limitation or am i missing something?
>
> thanks a lot for your invaluable help!


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Query by Class question and potential problem [message #603610 is a reply to message #75403] Wed, 14 March 2007 13:34 Go to previous message
Jean-Denis Boudreault is currently offline Jean-Denis BoudreaultFriend
Messages: 55
Registered: July 2009
Member
Thanks Martin,


well, actualyl thats what i meant by teneo uses the interface name. i know
in fact that it uses the EClass name, but in most cases, it will match the
interface (without the package); but i understand the subtillity.

now, i have a second question, which i almost posted in another thread,
but i will link to this one, since it is somewhat related (due to class
naming / specifying).

I believe that teneo does not support the @Proxy hibernate annotation, is
that correct? if so, is there any particular limitation for this
decision, or could it be implemented rapidly? i ask as if it is not there
yet, i may help to add it.

of course, this would imply of being able to specify fully specified class
names, and to be able to distinguish between the interface and the
implementation. and of course, if we add it for Proxy, could we also add
it for class name and/or entity-name? (or at least have the option to set
it). what do you think about adding @Proxy and potentially being able to
fully classify names in the hbm file?


thanks Martin
Re: Query by Class question and potential problem [message #603613 is a reply to message #75441] Wed, 14 March 2007 14:12 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Jean-Denis,
Yes I thought about allowing Teneo to run in different modes: mapping the model (for dynamic emf)
and mapping the classes (for specific cases where proxying is important). It is not that difficult
to replace the entityname in the mapping with the actual implementation classname. The attribute
name needs to be different in the class tag and the attribute should contain the actual impl classname.
The mapping logic uses the getEntityName method from the MappingContext class which already contains
some logic for getting the impl name. In addition the ERuntime.INSTANCE object can help to get the
interface for a certain eclass (to get the interfacename).

So if you are interested for your situation then please try it out to see if it can be changed to
real impl name and test it with proxying. If it works fine then this can be incorporated as a
separate mode-of-operation in Teneo.

gr. Martin

Jean-Denis Boudreault wrote:
> Thanks Martin,
>
>
> well, actualyl thats what i meant by teneo uses the interface name. i
> know in fact that it uses the EClass name, but in most cases, it will
> match the interface (without the package); but i understand the subtillity.
>
> now, i have a second question, which i almost posted in another thread,
> but i will link to this one, since it is somewhat related (due to class
> naming / specifying).
> I believe that teneo does not support the @Proxy hibernate annotation,
> is that correct? if so, is there any particular limitation for this
> decision, or could it be implemented rapidly? i ask as if it is not
> there yet, i may help to add it.
>
> of course, this would imply of being able to specify fully specified
> class names, and to be able to distinguish between the interface and the
> implementation. and of course, if we add it for Proxy, could we also add
> it for class name and/or entity-name? (or at least have the option to
> set it). what do you think about adding @Proxy and potentially being
> able to fully classify names in the hbm file?
>
>
> thanks Martin
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Query by Class question and potential problem [message #603620 is a reply to message #75457] Wed, 14 March 2007 14:48 Go to previous message
Jean-Denis Boudreault is currently offline Jean-Denis BoudreaultFriend
Messages: 55
Registered: July 2009
Member
ok, thanks. i will do so.


do you have any preferred method to switch naming modes for the class
name? do you wish to use an annotation (im not sure which one would do in
either JPA or hibernate?) or would you prefer some config file option? (a
config file option might make it hard to discriminate which entity should
be fully classified and which one is not, but might be needed if no
annotation can be used).


thanks for helping me define the switch and i will add this feature ASAP.


note: this is just a suggestion, but in the case that no hibernate or JPA
annotation can do, what do you think if we added teneo specific
annotations? They could later be used to specify other teneo specific
settings on entities and fields. just an idea of course.
Re: Query by Class question and potential problem [message #603639 is a reply to message #75492] Wed, 14 March 2007 15:20 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi J-D,
I prefer a global option for this (PersistenceOptions). The system can actually be made 'smarter',
it can detect if there is an implementation class for a eclass. If so it can map it as a real class.
If no impl. class can be found then the entity mapping can be used (the current behavior). This
behavior supports the combination of both dynamic emf and static emf.
As this is new behavior I would prefer a global persistence option which controls this (new or old
behavior). Later this can maybe be made the default.

Thanks!

gr. Martin

JD wrote:
> ok, thanks. i will do so.
>
>
> do you have any preferred method to switch naming modes for the class
> name? do you wish to use an annotation (im not sure which one would do
> in either JPA or hibernate?) or would you prefer some config file
> option? (a config file option might make it hard to discriminate which
> entity should be fully classified and which one is not, but might be
> needed if no annotation can be used).
>
> thanks for helping me define the switch and i will add this feature ASAP.
>
>
> note: this is just a suggestion, but in the case that no hibernate or
> JPA annotation can do, what do you think if we added teneo specific
> annotations? They could later be used to specify other teneo specific
> settings on entities and fields. just an idea of course.
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Query by Class question and potential problem [message #603655 is a reply to message #75575] Wed, 14 March 2007 16:46 Go to previous message
Jean-Denis Boudreault is currently offline Jean-Denis BoudreaultFriend
Messages: 55
Registered: July 2009
Member
created feature requests #177369 & #177370.
Previous Topic:[Teneo] Problem mapping Ecore package
Next Topic:[Teneo] Log output
Goto Forum:
  


Current Time: Thu Apr 18 20:14:56 GMT 2024

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

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

Back to the top