Teneo and Hibernate's Session.load() issue [message #127675] |
Tue, 29 July 2008 15:59 |
Mikhail Kadan Messages: 61 Registered: July 2009 |
Member |
|
|
Hi.
I have EMF model, which defines only one class "A", without any
attrinutes. I map this to DB using Teneo/Hibernate:
...
session.beginTransaction();
A a = TestFactory.eINSTANCE.createA();
Long aId = (Long) session.save(a);
session.getTransaction().commit();
...
Ok. Then I try to load this object from DB:
A a2 = (A) session.load("A", aId);
Works fine. But I need to load objects from DB not by EMF name, but by
interface/instance name/class. Hibernate provides me with such method:
A a3 = (A) session.load(A.class, aId);
But it fails with:
org.hibernate.MappingException: Unknown entity: test.A
So I look into generated "hibernate.hbm.xml":
<class name="test.impl.AImpl" entity-name="A" ...
So what do I think? Maybe Teneo places invalid value into "entity-name"
attribute for class mapping, so I cannot load classes by interface, and
have to provide name string w/o package specification? Of cource, I can
always get this string by traversing through EPackage.Registry, but its
very perfomance damaging option.
Thanks.
|
|
|
Re: Teneo and Hibernate's Session.load() issue [message #127688 is a reply to message #127675] |
Tue, 29 July 2008 16:12 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Mikhail,
You can control the entity-name in different ways (see the documentation on www.elver.org) for more
information. Teneo uses the hibernate entity-mapping because it makes it possible to support
dynamic-emf.
From a design point of view I find it nicer to use model concepts such as the eclassname than the
java implementation names. Having said that I fully understand that there are different views on this.
If a mapping has the entity-name set then hibernate throws errors when trying to use the classname
(as you try to do).
To disable the use of the entity-name there is a hidden feature (not tested) which you can enable as
follows.
1) Create your own class which inherits from org.eclipse.emf.teneo.hibernate.mapper.MappingContext
2) Override one method: forceUseOfInstance and let it return true.
3) Then do this:
dataStore.getExtensionManager().registerExtension(MappingCon text.class.getName(),
MyGreatMappingContext.class.getName();
before calling initialize on the datastore.
If you have time can you enter a bugzilla to make this option driven? Then I can add testcases for
this also.
btw, support for Teneo is given on the EMF newsgroup to which I cross-posted.
gr. Martin
Mikhail Kadan wrote:
> Hi.
>
> I have EMF model, which defines only one class "A", without any
> attrinutes. I map this to DB using Teneo/Hibernate:
>
> ...
> session.beginTransaction();
>
> A a = TestFactory.eINSTANCE.createA();
> Long aId = (Long) session.save(a);
>
> session.getTransaction().commit();
> ...
>
> Ok. Then I try to load this object from DB:
> A a2 = (A) session.load("A", aId);
>
> Works fine. But I need to load objects from DB not by EMF name, but by
> interface/instance name/class. Hibernate provides me with such method:
>
> A a3 = (A) session.load(A.class, aId);
>
> But it fails with:
>
> org.hibernate.MappingException: Unknown entity: test.A
>
> So I look into generated "hibernate.hbm.xml":
>
> <class name="test.impl.AImpl" entity-name="A" ...
>
> So what do I think? Maybe Teneo places invalid value into "entity-name"
> attribute for class mapping, so I cannot load classes by interface, and
> have to provide name string w/o package specification? Of cource, I can
> always get this string by traversing through EPackage.Registry, but its
> very perfomance damaging option.
>
> Thanks.
>
--
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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
|
|
Re: Teneo and Hibernate's Session.load() issue [message #620159 is a reply to message #127675] |
Tue, 29 July 2008 16:12 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Mikhail,
You can control the entity-name in different ways (see the documentation on www.elver.org) for more
information. Teneo uses the hibernate entity-mapping because it makes it possible to support
dynamic-emf.
From a design point of view I find it nicer to use model concepts such as the eclassname than the
java implementation names. Having said that I fully understand that there are different views on this.
If a mapping has the entity-name set then hibernate throws errors when trying to use the classname
(as you try to do).
To disable the use of the entity-name there is a hidden feature (not tested) which you can enable as
follows.
1) Create your own class which inherits from org.eclipse.emf.teneo.hibernate.mapper.MappingContext
2) Override one method: forceUseOfInstance and let it return true.
3) Then do this:
dataStore.getExtensionManager().registerExtension(MappingCon text.class.getName(),
MyGreatMappingContext.class.getName();
before calling initialize on the datastore.
If you have time can you enter a bugzilla to make this option driven? Then I can add testcases for
this also.
btw, support for Teneo is given on the EMF newsgroup to which I cross-posted.
gr. Martin
Mikhail Kadan wrote:
> Hi.
>
> I have EMF model, which defines only one class "A", without any
> attrinutes. I map this to DB using Teneo/Hibernate:
>
> ...
> session.beginTransaction();
>
> A a = TestFactory.eINSTANCE.createA();
> Long aId = (Long) session.save(a);
>
> session.getTransaction().commit();
> ...
>
> Ok. Then I try to load this object from DB:
> A a2 = (A) session.load("A", aId);
>
> Works fine. But I need to load objects from DB not by EMF name, but by
> interface/instance name/class. Hibernate provides me with such method:
>
> A a3 = (A) session.load(A.class, aId);
>
> But it fails with:
>
> org.hibernate.MappingException: Unknown entity: test.A
>
> So I look into generated "hibernate.hbm.xml":
>
> <class name="test.impl.AImpl" entity-name="A" ...
>
> So what do I think? Maybe Teneo places invalid value into "entity-name"
> attribute for class mapping, so I cannot load classes by interface, and
> have to provide name string w/o package specification? Of cource, I can
> always get this string by traversing through EPackage.Registry, but its
> very perfomance damaging option.
>
> Thanks.
>
--
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@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04273 seconds