Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Teneo and Named Queries
Teneo and Named Queries [message #98487] Fri, 05 October 2007 02:32 Go to next message
Eclipse UserFriend
Originally posted by: ydewit.gmail.com

I am so far quite impressed with the Teneo project after one day of using,
thanks for the great work!

I am using the JPA/EJB3 teneo interface to persist my EMF models but one
thing I can't figure out is how do I specify named queries with Teneo. I
looked at the documentation but didnt see any sections on that.

Ideally I would like to defined my named queries in the standard orm.xml
from JPA but it seems that Teneo is dynamically generating the hibernate
under the covers. Am I missing something?

thanks,

-- yuri
Re: Teneo and Named Queries [message #98501 is a reply to message #98487] Fri, 05 October 2007 08:06 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Yuri,
You are correct, Teneo generates a mapping when the datastore gets initialized. You can get to it by
calling getMappingXML on the datastore. You can also save this hbm in a file manually change it (by
adding named queries) and then use the file (see the options page on elver.org).

So except from manually changing the generated hbm there is currently no direct solution for what
you want. However a workaround would be the following.

1) Create a subclass of HbEntityDataStore and override the setPropertiesInConfiguration with this
method (I removed the log statements to make it clearer):

/** Sets the properties in the Hibernate Configuration. */
protected void setPropertiesInConfiguration() {
Properties properties = getHibernateProperties();
if (properties != null) {
if (getName() != null) {
getConfiguration().configure(getName(), properties);
} else {
getConfiguration().setProperties(properties);
}
} else if (getName() != null) {
getConfiguration().configure(name, Collections.emptyMap());
}
}

As you can see the configuration is configured using the name of the datastore.

2) Override the buildEntityManagerFactory method with this one:

/** Build the session factory */
protected EntityManagerFactory buildEntityManagerFactory() {
return getConfiguration().buildEntityManagerFactory();
}

3) Then you can define a persistence.xml in META-INF/ in your classpath specifying an additional
orm. xml (and other properties). The persistence unit name should have the same name as the datastore.

4) see also here:
http://www.elver.org/hibernate/hbdatastore.html#overriding

I have already worked with the above changes and it seemed to work fine with me.

Can you let me know if the above indeed works for you?

I will check the changes in later in cvs so then this is solved in the next build.

gr. Martin

Yuri wrote:
> I am so far quite impressed with the Teneo project after one day of
> using, thanks for the great work!
>
> I am using the JPA/EJB3 teneo interface to persist my EMF models but one
> thing I can't figure out is how do I specify named queries with Teneo. I
> looked at the documentation but didnt see any sections on that.
>
> Ideally I would like to defined my named queries in the standard orm.xml
> from JPA but it seems that Teneo is dynamically generating the hibernate
> under the covers. Am I missing something?
>
> thanks,
>
> -- yuri
>
>


--

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: Teneo and Named Queries [message #609899 is a reply to message #98487] Fri, 05 October 2007 08:06 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Yuri,
You are correct, Teneo generates a mapping when the datastore gets initialized. You can get to it by
calling getMappingXML on the datastore. You can also save this hbm in a file manually change it (by
adding named queries) and then use the file (see the options page on elver.org).

So except from manually changing the generated hbm there is currently no direct solution for what
you want. However a workaround would be the following.

1) Create a subclass of HbEntityDataStore and override the setPropertiesInConfiguration with this
method (I removed the log statements to make it clearer):

/** Sets the properties in the Hibernate Configuration. */
protected void setPropertiesInConfiguration() {
Properties properties = getHibernateProperties();
if (properties != null) {
if (getName() != null) {
getConfiguration().configure(getName(), properties);
} else {
getConfiguration().setProperties(properties);
}
} else if (getName() != null) {
getConfiguration().configure(name, Collections.emptyMap());
}
}

As you can see the configuration is configured using the name of the datastore.

2) Override the buildEntityManagerFactory method with this one:

/** Build the session factory */
protected EntityManagerFactory buildEntityManagerFactory() {
return getConfiguration().buildEntityManagerFactory();
}

3) Then you can define a persistence.xml in META-INF/ in your classpath specifying an additional
orm. xml (and other properties). The persistence unit name should have the same name as the datastore.

4) see also here:
http://www.elver.org/hibernate/hbdatastore.html#overriding

I have already worked with the above changes and it seemed to work fine with me.

Can you let me know if the above indeed works for you?

I will check the changes in later in cvs so then this is solved in the next build.

gr. Martin

Yuri wrote:
> I am so far quite impressed with the Teneo project after one day of
> using, thanks for the great work!
>
> I am using the JPA/EJB3 teneo interface to persist my EMF models but one
> thing I can't figure out is how do I specify named queries with Teneo. I
> looked at the documentation but didnt see any sections on that.
>
> Ideally I would like to defined my named queries in the standard orm.xml
> from JPA but it seems that Teneo is dynamically generating the hibernate
> under the covers. Am I missing something?
>
> thanks,
>
> -- yuri
>
>


--

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
Previous Topic:Teneo and Named Queries
Next Topic:problem about emf+jpox query
Goto Forum:
  


Current Time: Sat Jul 27 11:16:45 GMT 2024

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

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

Back to the top