Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Need ClassMetadata but it's not present
[Teneo] Need ClassMetadata but it's not present [message #677233] Tue, 07 June 2011 21:36 Go to next message
Mike Cooper is currently offline Mike CooperFriend
Messages: 60
Registered: February 2011
Member
I'm trying to get a Vaadin Hibernate Container (HbnContainer) to work with my Teneo based datastore. There is an HbnContainer add-on class supplied by the Vaadin folks which I'm trying to use with one of the Teneo model managed classes I have. The HbnContainer makes extensive use of ClassMetadata from the SessionFactory. In particular HbnContainer uses the getPropertyType, getIdentifier, getIdentifierType, getIdentifierProperty methods.

Unfortunately my instantiated HbDataStore.getSessionFactory().getClassMetadata() returns null. The SessionFactory() seems to work fine for all my other "normal" uses (mainly getting Session).

My Teneo model is being loaded from a .ecorediag -> .ecore -> .genmodel file.

So my questions are:

1) Is HbDataStore.getSessionFactory().getClassMetadata() suppose to return a real ClassMetadata or is this not supported with Teneo?
2) If getClassMetadata() is suppose to work, any suggestions on what I'm missing?
3) If getClassMetadata() is not supported, any suggestions for getting similar data to getPropertyType, getIdentifier, getIdentifierType, getIdentifierProperty?

URL for HbnContainer: http://vaadin.com/directory#addon/hbncontainer
Re: [Teneo] Need ClassMetadata but it's not present [message #677327 is a reply to message #677233] Wed, 08 June 2011 07:58 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi,
Yes getClassMetaData is supposed to work, the getSessionFactory returns a plain/standard Hibernate SessionFactory
implementation (no Teneo overrides there). But I think that the 'problem' is in the parameter passed to the
getClassMetaData, maybe Vaadin uses the classname or the class while Teneo maps using entity names. I guess that is the
thing to check.

Btw, Teneo questions are answered on the main EMF newsgroup, which I added as a cc.

And if you are using EMF in a web server environment (so not RCP) then it can make sense to checkout the Texo projects,
it generates real pojo's (no EMF compile dependencies) while still supporting many/most EMF concepts (XML serialization,
featuremaps, etc.).
http://wiki.eclipse.org/Texo

gr. Martin

On 06/07/2011 11:36 PM, forums-noreply@eclipse.org wrote:
> I'm trying to get a Vaadin Hibernate Container (HbnContainer) to work with my Teneo based datastore. There is an
> HbnContainer add-on class supplied by the Vaadin folks which I'm trying to use with one of the Teneo model managed
> classes I have. The HbnContainer makes extensive use of ClassMetadata from the SessionFactory. In particular
> HbnContainer uses the getPropertyType, getIdentifier, getIdentifierType, getIdentifierProperty methods.
>
> Unfortunately my instantiated HbDataStore.getSessionFactory().getClassMetadata() returns null. The SessionFactory()
> seems to work fine for all my other "normal" uses (mainly getting Session).
>
> My Teneo model is being loaded from a .ecorediag -> .ecore -> .genmodel file.
>
> So my questions are:
>
> 1) Is HbDataStore.getSessionFactory().getClassMetadata() suppose to return a real ClassMetadata or is this not supported
> with Teneo?
> 2) If getClassMetadata() is suppose to work, any suggestions on what I'm missing?
> 3) If getClassMetadata() is not supported, any suggestions for getting similar data to getPropertyType, getIdentifier,
> getIdentifierType, getIdentifierProperty?
>
> URL for HbnContainer: http://vaadin.com/directory#addon/hbncontainer
>


--

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] Need ClassMetadata but it's not present [message #677480 is a reply to message #677327] Wed, 08 June 2011 16:08 Go to previous messageGo to next message
Mike Cooper is currently offline Mike CooperFriend
Messages: 60
Registered: February 2011
Member
Hi Martin,

Many thanks for the info!

I'm a bit confused when you say the parameter passed to getClassMetadata() since that method takes no arguments. When I look at the HbnContainer examples it appears that the Class is being configured with AnnotationConfiguration like this:

AnnotationConfiguration cnf = new AnnotationConfiguration();
<...delete other config...>
            cnf.addAnnotatedClass(Workout.class);
            cnf.addAnnotatedClass(Type.class);
            sessionFactory = cnf.buildSessionFactory();

In this case Workout and Type are the classes. You can do something similar with Configuration class as well. I'm assuming the addAnnotatedClass method is what tells hibernate's SessionFactory what class to return in getClassMetadata, but I'm not sure of this.

Is there some means of doing the above with Teneo? i.e. Pass along a Configuration instance which has my model class set via setClass or setAnnotatedClass?

Best regards,
mike
Re: [Teneo] Need ClassMetadata but it's not present [message #677600 is a reply to message #677480] Wed, 08 June 2011 22:02 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi,
I will answer your post in the main emf newsgroup.

gr. Martin

On 06/08/2011 06:08 PM, forums-noreply@eclipse.org wrote:
> Hi Martin,
>
> Many thanks for the info!
> I'm a bit confused when you say the parameter passed to getClassMetadata() since that method takes no arguments. When I
> look at the HbnContainer examples it appears that the Class is being configured with AnnotationConfiguration like this:
>
>
> AnnotationConfiguration cnf = new AnnotationConfiguration();
> <...delete other config...>
> cnf.addAnnotatedClass(Workout.class);
> cnf.addAnnotatedClass(Type.class);
> sessionFactory = cnf.buildSessionFactory();
>
> In this case Workout and Type are the classes. You can do something similar with Configuration class as well. I'm
> assuming the addAnnotatedClass method is what tells hibernate's SessionFactory what class to return in getClassMetadata,
> but I'm not sure of this.
>
> Is there some means of doing the above with Teneo? i.e. Pass along a Configuration instance which has my model class set
> via setClass or setAnnotatedClass?
>
> Best regards,
> mike
>


--

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] Need ClassMetadata but it's not present [message #681712 is a reply to message #677600] Thu, 09 June 2011 17:22 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Now answering in the EMFT newsgroup because the reply in the EMF newsgroup does not seem to be visible in the web ui.
Let's continue in this newsgroup.

Hi Mike,
Now I am confused :-), this (see below) is the signature of the 2 getClassMetaData methods in the Hibernate
SessionFactory interface, they both take a parameter. Or do you mean another object (than SessionFactory)?

Teneo generates a hbm mapping in-memory and maps using the entity name (eclass name mostly). Teneo adds different kinds
of mapping information to make sure that different EMF constructs work correctly, so it not possible to directly add EMF
generated classes to the configuration object (this is different with Texo).

/**
* Retrieve the {@link ClassMetadata} associated with the given entity class.
*
* @param entityClass The entity class
*
* @return The metadata associated with the given entity; may be null if no such
* entity was mapped.
*
* @throws HibernateException Generally null is returned instead of throwing.
*/
public ClassMetadata getClassMetadata(Class entityClass);

/**
* Retrieve the {@link ClassMetadata} associated with the given entity class.
*
* @param entityName The entity class
*
* @return The metadata associated with the given entity; may be null if no such
* entity was mapped.
*
* @throws HibernateException Generally null is returned instead of throwing.
* @since 3.0
*/
public ClassMetadata getClassMetadata(String entityName);





On 06/09/2011 12:02 AM, Martin Taal wrote:
> Hi,
> I will answer your post in the main emf newsgroup.
>
> gr. Martin
>
> On 06/08/2011 06:08 PM, forums-noreply@eclipse.org wrote:
>> Hi Martin,
>>
>> Many thanks for the info!
>> I'm a bit confused when you say the parameter passed to getClassMetadata() since that method takes no arguments. When I
>> look at the HbnContainer examples it appears that the Class is being configured with AnnotationConfiguration like this:
>>
>>
>> AnnotationConfiguration cnf = new AnnotationConfiguration();
>> <...delete other config...>
>> cnf.addAnnotatedClass(Workout.class);
>> cnf.addAnnotatedClass(Type.class);
>> sessionFactory = cnf.buildSessionFactory();
>>
>> In this case Workout and Type are the classes. You can do something similar with Configuration class as well. I'm
>> assuming the addAnnotatedClass method is what tells hibernate's SessionFactory what class to return in getClassMetadata,
>> but I'm not sure of this.
>>
>> Is there some means of doing the above with Teneo? i.e. Pass along a Configuration instance which has my model class set
>> via setClass or setAnnotatedClass?
>>
>> Best regards,
>> mike
>>
>
>


--

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] Need ClassMetadata but it's not present [message #681774 is a reply to message #681712] Thu, 09 June 2011 20:37 Go to previous messageGo to next message
Mike Cooper is currently offline Mike CooperFriend
Messages: 60
Registered: February 2011
Member
Hi Martin,

No, you are not crazy. I am. There is a getClassMetadata() method in the HbnContainer class which is a frontend for SessionFactory.getClassMetadata(Class arg). I was thinking of the getClassMetadata() (no arg) frontend. Sorry about that.

When the HbnContainer is created it takes a Class arg for the Hibernate class to use. e.g. If you have a Hibernate annotated class called Workout you pass Workout.class as the arg to new HbnContainer().

I'm a bit puzzled by what teneo built class to give to HbnContainer(). My model has a medium level of complexity with a dozen or so entity's. I'm trying to get HbnContainer to "read" one of these teneo classes, but the real SessionFactory.getClassMetadata(myclass) returns null. I've tried using the "top" level ModelPackage and ModelFactory classes as well with the same result.

I realize this sounds a bit like I'm asking you for help with this third-party HbnContainer(), but what I'm trying to get at is how this would work in a pure Hibernate project. I would expect that if I had an annotated pure Hibernate class called Workout I would just pass Workout.class as the arg to SessionFactory.getClassMetadata(). Is that right?

Thanks again.
mike
Re: [Teneo] Need ClassMetadata but it's not present [message #682326 is a reply to message #681774] Fri, 10 June 2011 20:38 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Mike,
Teneo maps using entity names, so if possible you should use the getClassMetaData method which expects a string and pass
it the entity name. Is that possible?

gr. Martin

On 06/09/2011 10:37 PM, forums-noreply@eclipse.org wrote:
> Hi Martin,
>
> No, you are not crazy. I am. There is a getClassMetadata() method in the HbnContainer class which is a frontend for
> SessionFactory.getClassMetadata(Class arg). I was thinking of the getClassMetadata() (no arg) frontend. Sorry about that.
>
> When the HbnContainer is created it takes a Class arg for the Hibernate class to use. e.g. If you have a Hibernate
> annotated class called Workout you pass Workout.class as the arg to new HbnContainer().
>
> I'm a bit puzzled by what teneo built class to give to HbnContainer(). My model has a medium level of complexity with a
> dozen or so entity's. I'm trying to get HbnContainer to "read" one of these teneo classes, but the real
> SessionFactory.getClassMetadata(myclass) returns null. I've tried using the "top" level ModelPackage and ModelFactory
> classes as well with the same result.
>
> I realize this sounds a bit like I'm asking you for help with this third-party HbnContainer(), but what I'm trying to
> get at is how this would work in a pure Hibernate project. I would expect that if I had an annotated pure Hibernate
> class called Workout I would just pass Workout.class as the arg to SessionFactory.getClassMetadata(). Is that right?
>
> Thanks again.
> mike
>


--

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] Need ClassMetadata but it's not present [message #682355 is a reply to message #682326] Fri, 10 June 2011 22:59 Go to previous messageGo to next message
Mike Cooper is currently offline Mike CooperFriend
Messages: 60
Registered: February 2011
Member
Hi Martin,

Passing the entity name as a String to [xxx] does get me over this major hurdle. Thanks for that!

Unfortunately HbnContainer uses a number of different methods for the entity class. e.g.

sessionManager.getSession().createCriteria(type)
pojo = (T) sessionManager.getSession().get(type, id)
Field idField = type.getDeclaredField(idName)
pojo = (T) sessionManager.getSession().get(type,
(Serializable) getIdForPojo(pojo));
type.newInstance()

where type is the entity class. Is there some way of getting the entity class using the entity name String from SessionManager? There is a SessionManager.getSession().getEntityName(Object arg) which returns String, but that's all I see.

Cheers,
mike
Re: [Teneo] Need ClassMetadata but it's not present [message #683205 is a reply to message #682355] Mon, 13 June 2011 08:11 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Mike,
The data store has this method:
getPersistentClass(String entityName)
which returns the Hibernate persistent class, but I am not sure if the persistentclass contains the java implementation
class, you need to check what gets returned.

There is the EModelResolver class, but it is only set after the datastore has been initialized:
EModelResolver.getInstance().getJavaClass(EClassifier eClassifier)

Note that the PersistenceOptions.ALSO_MAP_AS_CLASS option influences the mapping, but its default value should be fine.

gr. Martin

On 06/11/2011 12:59 AM, forums-noreply@eclipse.org wrote:
> Hi Martin,
>
> Passing the entity name as a String to [xxx] does get me over this major hurdle. Thanks for that!
> Unfortunately HbnContainer uses a number of different methods for the entity class. e.g.
> sessionManager.getSession().createCriteria(type) pojo = (T) sessionManager.getSession().get(type, id)
> Field idField = type.getDeclaredField(idName)
> pojo = (T) sessionManager.getSession().get(type,
> (Serializable) getIdForPojo(pojo));
> type.newInstance()
>
> where type is the entity class. Is there some way of getting the entity class using the entity name String from
> SessionManager? There is a SessionManager.getSession().getEntityName(Object arg) which returns String, but that's all I
> see.
>
> Cheers,
> mike
>


--

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] Need ClassMetadata but it's not present [message #683931 is a reply to message #683205] Tue, 14 June 2011 17:29 Go to previous messageGo to next message
Mike Cooper is currently offline Mike CooperFriend
Messages: 60
Registered: February 2011
Member
Hi Martin,

Thanks for those excellent pointers! It looks like the EModelResolver will get me the right class!

Unfortunately I'm now hitting an issue with SessionFactory.getClassMetadata() returning null. As a test if I do something like this:

getSessionFactory().getClassMetadata(Asset.class);
- or -
getSessionFactory().getClassMetadata(AssetImpl.class);

I get a null result. Asset is the autogenerated interface and AssetImpl the autogenerated implementation class.

getClassMetadata says it takes "Class entityClass" an argument. Any hints as what I'm doing wrong? I'm sure it's some kind of newbie thing I'm missing. Sad

Cheers,
mike
Re: [Teneo] Need ClassMetadata but it's not present [message #689764 is a reply to message #683931] Tue, 28 June 2011 10:06 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Mike,
There is also this one:

public ClassMetadata getClassMetadata(String entityName);

normally the entity name is the same as the EClass name. Can you use that?

gr. Martin
Previous Topic:[EEF] Migrate 1.0 Not using EMF ItemProvider
Next Topic:EMFIndex still an active projecct?
Goto Forum:
  


Current Time: Wed Nov 25 21:04:30 GMT 2020

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

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

Back to the top