Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Teneo] Integrating Teneo-Struts-Tomcat
[Teneo] Integrating Teneo-Struts-Tomcat [message #82825] Thu, 10 May 2007 10:33 Go to next message
Eclipse UserFriend
Originally posted by: gonzalinlinWITHOUT_THIS.tiscali.es

Hello!



I'm developing a web application. I've used EMF to generate my model. Then,
I used Teneo to persist my classes. But when I try to integrate my
View-Controller (Tomcat-JSP-Struts) with Teneo, problems arise.



I followed the "Using Hibernate with Tomcat" tutorial in
http://www.hibernate.org/114.html, but I think there must be something
different when using Teneo.



Does anyone has experience with this kind of topic or can point me to a
good doc about it?



Thanks in advance!



With regards,



Gonzalo
Re: [Teneo] Integrating Teneo-Struts-Tomcat [message #82856 is a reply to message #82825] Thu, 10 May 2007 10:43 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Gonzalo,
I am building a webapp using teneo/emf, hibernate and jsf (and tomcat) and it works fine. What are
the problems you are getting?

gr. Martin

Gonzalo wrote:
> Hello!
>
>
>
> I'm developing a web application. I've used EMF to generate my model. Then,
> I used Teneo to persist my classes. But when I try to integrate my
> View-Controller (Tomcat-JSP-Struts) with Teneo, problems arise.
>
>
>
> I followed the "Using Hibernate with Tomcat" tutorial in
> http://www.hibernate.org/114.html, but I think there must be something
> different when using Teneo.
>
>
>
> Does anyone has experience with this kind of topic or can point me to a
> good doc about it?
>
>
>
> Thanks in advance!
>
>
>
> With regards,
>
>
>
> Gonzalo
>
>


--

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] Integrating Teneo-Struts-Tomcat [message #82871 is a reply to message #82825] Thu, 10 May 2007 10:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Gonzalo,

I'm not familiar with how you'd use JSP-Struts, but I do recall in the
past some folks complaining that because their List was surfaced as an
EList, struts didn't like it. So perhaps using the GenModel's Suppress
EMF Types flag to surface ELists as just Lists in the API would help
with that. Could you say a little bit about what type of problem arises?


Gonzalo wrote:
> Hello!
>
>
>
> I'm developing a web application. I've used EMF to generate my model. Then,
> I used Teneo to persist my classes. But when I try to integrate my
> View-Controller (Tomcat-JSP-Struts) with Teneo, problems arise.
>
>
>
> I followed the "Using Hibernate with Tomcat" tutorial in
> http://www.hibernate.org/114.html, but I think there must be something
> different when using Teneo.
>
>
>
> Does anyone has experience with this kind of topic or can point me to a
> good doc about it?
>
>
>
> Thanks in advance!
>
>
>
> With regards,
>
>
>
> Gonzalo
>
>
>
Re: [Teneo] Integrating Teneo-Struts-Tomcat [message #82931 is a reply to message #82856] Thu, 10 May 2007 11:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: gonzalinlinWITHOUT_THIS.tiscali.es

Hi Martin,

I can't get the data persisted. I think this is a configuration problem.
Before, I initialized the Teneo Runtime in the Actions (Struts). But now, I
created a similar class to this one:

public class HibernateListener implements ServletContextListener {

public void contextInitialized(ServletContextEvent event) {
final Properties persistenceProps = new Properties();
persistenceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX); final String
dataStoreName = "mayo"; final HbDataStore dataStore =
(HbDataStore)HbHelper.INSTANCE.createRegisterDataStore(dataS toreName);
dataStore.setPersistenceProperties(persistenceProps);
dataStore.setEPackages(new EPackage[] { party.PartyPackage.eINSTANCE,
productoexpediente.presupuesto.PresupuestoPackage.eINSTANCE,
productoexpediente.factura.FacturaPackage.eINSTANCE,
productoexpediente.ProductoexpedientePackage.eINSTANCE});
dataStore.initialize(); final SessionFactory sessionFactory =
dataStore.getSessionFactory();
}

public void contextDestroyed(ServletContextEvent event) {
// TO DO }
}and created a <listener> tag into the web.xml. I think this is right,
because when Tomcat starts, dataStore.initialize() is called.

When I try to open a session in each of my actions, I need:
final Session session = sessionFactory.openSession();

but, how can the action access to the sessionFactory (in HibernateListener
class and loaded into Tomcat through the <listener> tag) in order to open a
session?

With regards,

Gonzalo


"Martin Taal" <mtaal@elver.org> escribi
Re: [Teneo] Integrating Teneo-Struts-Tomcat [message #82946 is a reply to message #82931] Thu, 10 May 2007 11:39 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Gonzalo,
There are different schools of thought to solve this. To react on your question. The most simple is
just put the sessionfactory in a static singleton somewhere and get it from there when you need it.
Each action will then open and close a session/transaction. This is nice and simple and works fine
if your app uses one sessionfactory (is true for most apps).

Another approach which is very popular is called 'open session in view'. Basically you use a servlet
request filter to intercept all the requests for the database oriented pages. In the request filter
you open a session (from a sessionfactory which you have put in a static singleton somewhere) and
put the session in a threadlocal,
then pass the request on (call chain.doFilter). You application code can then get to the session
through the threadlocal. Then when the request finishes you commit the transaction or rollback (in
case of a transaction).
The nice thing of this approach is that only one session/transaction is opened for one request and
there is much less session/transaction code in your application code.

See here for more info and example code:
http://www.hibernate.org/43.html

gr. Martin

Gonzalo wrote:
> Hi Martin,
>
> I can't get the data persisted. I think this is a configuration problem.
> Before, I initialized the Teneo Runtime in the Actions (Struts). But now, I
> created a similar class to this one:
>
> public class HibernateListener implements ServletContextListener {
>
> public void contextInitialized(ServletContextEvent event) {
> final Properties persistenceProps = new Properties();
> persistenceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX); final String
> dataStoreName = "mayo"; final HbDataStore dataStore =
> (HbDataStore)HbHelper.INSTANCE.createRegisterDataStore(dataS toreName);
> dataStore.setPersistenceProperties(persistenceProps);
> dataStore.setEPackages(new EPackage[] { party.PartyPackage.eINSTANCE,
> productoexpediente.presupuesto.PresupuestoPackage.eINSTANCE,
> productoexpediente.factura.FacturaPackage.eINSTANCE,
> productoexpediente.ProductoexpedientePackage.eINSTANCE});
> dataStore.initialize(); final SessionFactory sessionFactory =
> dataStore.getSessionFactory();
> }
>
> public void contextDestroyed(ServletContextEvent event) {
> // TO DO }
> }and created a <listener> tag into the web.xml. I think this is right,
> because when Tomcat starts, dataStore.initialize() is called.
>
> When I try to open a session in each of my actions, I need:
> final Session session = sessionFactory.openSession();
>
> but, how can the action access to the sessionFactory (in HibernateListener
> class and loaded into Tomcat through the <listener> tag) in order to open a
> session?
>
> With regards,
>
> Gonzalo
>
>
> "Martin Taal" <mtaal@elver.org> escribió en el mensaje
> news:f1ut1a$cnn$1@build.eclipse.org...
>> Hi Gonzalo,
>> I am building a webapp using teneo/emf, hibernate and jsf (and tomcat) and
>> it works fine. What are the problems you are getting?
>>
>> gr. Martin
>>
>> Gonzalo wrote:
>>> Hello!
>>>
>>>
>>>
>>> I'm developing a web application. I've used EMF to generate my model.
>>> Then, I used Teneo to persist my classes. But when I try to integrate my
>>> View-Controller (Tomcat-JSP-Struts) with Teneo, problems arise.
>>>
>>>
>>>
>>> I followed the "Using Hibernate with Tomcat" tutorial in
>>> http://www.hibernate.org/114.html, but I think there must be something
>>> different when using Teneo.
>>>
>>>
>>>
>>> Does anyone has experience with this kind of topic or can point me to a
>>> good doc about it?
>>>
>>>
>>>
>>> Thanks in advance!
>>>
>>>
>>>
>>> With regards,
>>>
>>>
>>>
>>> Gonzalo
>>>
>>>
>>
>> --
>>
>> 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
>
>


--

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] Integrating Teneo-Struts-Tomcat [message #83399 is a reply to message #82946] Sat, 12 May 2007 18:41 Go to previous message
Eclipse UserFriend
Originally posted by: gonzalinlinREMOVE_THIS.tiscali.es

Hi Martin,
I followed your advice. I got it! Now my data is persisted from the web
view.

Thank you again!

With regards,

Gonzalo

"Martin Taal" <mtaal@elver.org> escribi
Re: [Teneo] Integrating Teneo-Struts-Tomcat [message #606653 is a reply to message #82825] Thu, 10 May 2007 10:43 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Gonzalo,
I am building a webapp using teneo/emf, hibernate and jsf (and tomcat) and it works fine. What are
the problems you are getting?

gr. Martin

Gonzalo wrote:
> Hello!
>
>
>
> I'm developing a web application. I've used EMF to generate my model. Then,
> I used Teneo to persist my classes. But when I try to integrate my
> View-Controller (Tomcat-JSP-Struts) with Teneo, problems arise.
>
>
>
> I followed the "Using Hibernate with Tomcat" tutorial in
> http://www.hibernate.org/114.html, but I think there must be something
> different when using Teneo.
>
>
>
> Does anyone has experience with this kind of topic or can point me to a
> good doc about it?
>
>
>
> Thanks in advance!
>
>
>
> With regards,
>
>
>
> Gonzalo
>
>


--

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] Integrating Teneo-Struts-Tomcat [message #606654 is a reply to message #82825] Thu, 10 May 2007 10:45 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31832
Registered: July 2009
Senior Member
Gonzalo,

I'm not familiar with how you'd use JSP-Struts, but I do recall in the
past some folks complaining that because their List was surfaced as an
EList, struts didn't like it. So perhaps using the GenModel's Suppress
EMF Types flag to surface ELists as just Lists in the API would help
with that. Could you say a little bit about what type of problem arises?


Gonzalo wrote:
> Hello!
>
>
>
> I'm developing a web application. I've used EMF to generate my model. Then,
> I used Teneo to persist my classes. But when I try to integrate my
> View-Controller (Tomcat-JSP-Struts) with Teneo, problems arise.
>
>
>
> I followed the "Using Hibernate with Tomcat" tutorial in
> http://www.hibernate.org/114.html, but I think there must be something
> different when using Teneo.
>
>
>
> Does anyone has experience with this kind of topic or can point me to a
> good doc about it?
>
>
>
> Thanks in advance!
>
>
>
> With regards,
>
>
>
> Gonzalo
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Teneo] Integrating Teneo-Struts-Tomcat [message #606658 is a reply to message #82856] Thu, 10 May 2007 11:21 Go to previous message
Gonzalo is currently offline GonzaloFriend
Messages: 27
Registered: July 2009
Junior Member
Hi Martin,

I can't get the data persisted. I think this is a configuration problem.
Before, I initialized the Teneo Runtime in the Actions (Struts). But now, I
created a similar class to this one:

public class HibernateListener implements ServletContextListener {

public void contextInitialized(ServletContextEvent event) {
final Properties persistenceProps = new Properties();
persistenceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX); final String
dataStoreName = "mayo"; final HbDataStore dataStore =
(HbDataStore)HbHelper.INSTANCE.createRegisterDataStore(dataS toreName);
dataStore.setPersistenceProperties(persistenceProps);
dataStore.setEPackages(new EPackage[] { party.PartyPackage.eINSTANCE,
productoexpediente.presupuesto.PresupuestoPackage.eINSTANCE,
productoexpediente.factura.FacturaPackage.eINSTANCE,
productoexpediente.ProductoexpedientePackage.eINSTANCE});
dataStore.initialize(); final SessionFactory sessionFactory =
dataStore.getSessionFactory();
}

public void contextDestroyed(ServletContextEvent event) {
// TO DO }
}and created a <listener> tag into the web.xml. I think this is right,
because when Tomcat starts, dataStore.initialize() is called.

When I try to open a session in each of my actions, I need:
final Session session = sessionFactory.openSession();

but, how can the action access to the sessionFactory (in HibernateListener
class and loaded into Tomcat through the <listener> tag) in order to open a
session?

With regards,

Gonzalo


"Martin Taal" <mtaal@elver.org> escribi
Re: [Teneo] Integrating Teneo-Struts-Tomcat [message #606659 is a reply to message #82931] Thu, 10 May 2007 11:39 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Gonzalo,
There are different schools of thought to solve this. To react on your question. The most simple is
just put the sessionfactory in a static singleton somewhere and get it from there when you need it.
Each action will then open and close a session/transaction. This is nice and simple and works fine
if your app uses one sessionfactory (is true for most apps).

Another approach which is very popular is called 'open session in view'. Basically you use a servlet
request filter to intercept all the requests for the database oriented pages. In the request filter
you open a session (from a sessionfactory which you have put in a static singleton somewhere) and
put the session in a threadlocal,
then pass the request on (call chain.doFilter). You application code can then get to the session
through the threadlocal. Then when the request finishes you commit the transaction or rollback (in
case of a transaction).
The nice thing of this approach is that only one session/transaction is opened for one request and
there is much less session/transaction code in your application code.

See here for more info and example code:
http://www.hibernate.org/43.html

gr. Martin

Gonzalo wrote:
> Hi Martin,
>
> I can't get the data persisted. I think this is a configuration problem.
> Before, I initialized the Teneo Runtime in the Actions (Struts). But now, I
> created a similar class to this one:
>
> public class HibernateListener implements ServletContextListener {
>
> public void contextInitialized(ServletContextEvent event) {
> final Properties persistenceProps = new Properties();
> persistenceProps.setProperty(PersistenceOptions.QUALIFY_ENTI TY_NAME,
> PersistenceOptions.QUALIFY_ENTITY_NAME_NSPREFIX); final String
> dataStoreName = "mayo"; final HbDataStore dataStore =
> (HbDataStore)HbHelper.INSTANCE.createRegisterDataStore(dataS toreName);
> dataStore.setPersistenceProperties(persistenceProps);
> dataStore.setEPackages(new EPackage[] { party.PartyPackage.eINSTANCE,
> productoexpediente.presupuesto.PresupuestoPackage.eINSTANCE,
> productoexpediente.factura.FacturaPackage.eINSTANCE,
> productoexpediente.ProductoexpedientePackage.eINSTANCE});
> dataStore.initialize(); final SessionFactory sessionFactory =
> dataStore.getSessionFactory();
> }
>
> public void contextDestroyed(ServletContextEvent event) {
> // TO DO }
> }and created a <listener> tag into the web.xml. I think this is right,
> because when Tomcat starts, dataStore.initialize() is called.
>
> When I try to open a session in each of my actions, I need:
> final Session session = sessionFactory.openSession();
>
> but, how can the action access to the sessionFactory (in HibernateListener
> class and loaded into Tomcat through the <listener> tag) in order to open a
> session?
>
> With regards,
>
> Gonzalo
>
>
> "Martin Taal" <mtaal@elver.org> escribió en el mensaje
> news:f1ut1a$cnn$1@build.eclipse.org...
>> Hi Gonzalo,
>> I am building a webapp using teneo/emf, hibernate and jsf (and tomcat) and
>> it works fine. What are the problems you are getting?
>>
>> gr. Martin
>>
>> Gonzalo wrote:
>>> Hello!
>>>
>>>
>>>
>>> I'm developing a web application. I've used EMF to generate my model.
>>> Then, I used Teneo to persist my classes. But when I try to integrate my
>>> View-Controller (Tomcat-JSP-Struts) with Teneo, problems arise.
>>>
>>>
>>>
>>> I followed the "Using Hibernate with Tomcat" tutorial in
>>> http://www.hibernate.org/114.html, but I think there must be something
>>> different when using Teneo.
>>>
>>>
>>>
>>> Does anyone has experience with this kind of topic or can point me to a
>>> good doc about it?
>>>
>>>
>>>
>>> Thanks in advance!
>>>
>>>
>>>
>>> With regards,
>>>
>>>
>>>
>>> Gonzalo
>>>
>>>
>>
>> --
>>
>> 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
>
>


--

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] Integrating Teneo-Struts-Tomcat [message #606690 is a reply to message #82946] Sat, 12 May 2007 18:41 Go to previous message
Gonzalo is currently offline GonzaloFriend
Messages: 27
Registered: July 2009
Junior Member
Hi Martin,
I followed your advice. I got it! Now my data is persisted from the web
view.

Thank you again!

With regards,

Gonzalo

"Martin Taal" <mtaal@elver.org> escribi
Previous Topic:[teneo] eContainer is set null in inverseAdd() when adding new element into Resource's contentEList
Next Topic:cascaded deletes
Goto Forum:
  


Current Time: Thu Apr 15 02:49:56 GMT 2021

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

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

Back to the top