Tapestry Hibernate Sessions

2011-06-10 Thread Tony Nelson
Hi all,

I'm in the process of rebuilding an app that was done in Tap3 (indeed!) in 
Tap5.  It's a small app, maybe a dozen pages used by my internal staff.  This 
is in preparation for rebuilding the entire front of a much larger app.  But 
that's a story for another day.

Because I want to learn all the new Tap5 goodness, I started with an new 
project built w/ the maven archetype.  I copied over my DB classes and added 
the Spring dependencies I needed, and wrote a test case to make sure I could 
read and write from my dev (h2) database.

Then I created a very small page that displays a few rows from the DB in a 
table.  The service method is trivial:

@Log
public ListOffice getOffices() {
return officeDao.getAllOffices(); 
}

I fired up Jetty, and opened the page.  I really expected to get an exception 
saying that I don't have a database session because I purposely did not include 
the OpenSessionInView filter that I'm familiar with.  In addition I didn't 
include the tapestry-hibernate jars because I'm not sure if it's better to have 
Tap of Spring handle opening and closing the sessions.

I was very surprised when the page actually rendered a result from the 
database.  I'm still not clear where the session is coming from, but that is 
actually my problem.  I can reload my tiny test page 8 times.  On the 9th time, 
I see:

[582385532@qtp-918884489-5] DEBUG com.starpoint.helpdesk.pages.Offices  - 
[ENTER] getOffices()

And the browser spins.  I can open the H2 DB in the H2 admin console and issue 
queries against it, so the H2 instance is fine.

Obviously I'm either out of sessions or connection pool slots.  My goal is to 
be able to use the Spring @Transactional annotation because in the larger app 
rewrite I have several dozen business layer Spring managed beans that depend on 
it.

I have tried adding Springs OpenSessionInViewFilter, and I've tried adding a 
dependency on tapestry-hibernate-core.  Neither of these solutions have helped.

Can anyone offer any suggestions as to where the session is actually coming 
from so that I can try to figure out how to get the session closed or released?

I have Spring configured like this:

?xml version=1.0 encoding=UTF-8?
beans xmlns=http://www.springframework.org/schema/beans;
   xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
   xmlns:context=http://www.springframework.org/schema/context;
   xsi:schemaLocation=http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd;
default-autowire=byName 

bean id=dataSource class=org.apache.commons.dbcp.BasicDataSource
property name=driverClassName value=${dataSource.driverClass} /
property name=username value=${dataSource.user} /
property name=password value=${dataSource.password} /
property name=url value=${dataSource.jdbcURL} /
/bean

!-- Hibernate session factory --
bean id=sessionFactory
  
class=org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
property name=dataSource ref=dataSource/
property name=configLocation value=classpath:/hibernate.cfg.xml/
/bean

!-- Hibernate transaction manager --
bean id=transactionManager
  
class=org.springframework.orm.hibernate3.HibernateTransactionManager
property name=sessionFactory ref=sessionFactory/
/bean


context:component-scan base-package=com.starpoint.helpdesk.dao /
context:annotation-config/

/beans

and my web.xml is simply:

?xml version=1.0 encoding=UTF-8?
!DOCTYPE web-app
PUBLIC -//Sun Microsystems, Inc.//DTD Web Application 2.3//EN
http://java.sun.com/dtd/web-app_2_3.dtd;
web-app
display-nameStarpoint Help Desk Tapestry 5 Application/display-name

context-param
!--
The only significant configuration for Tapestry 5, this informs 
Tapestry
of where to look for pages, components and mixins.
--
param-nametapestry.app-package/param-name
param-valuecom.starpoint.helpdesk/param-value
/context-param

context-param
param-namecontextConfigLocation/param-name
param-valueclasspath:/applicationContext.xml/param-value
/context-param

filter
filter-nameapp/filter-name

filter-classorg.apache.tapestry5.spring.TapestrySpringFilter/filter-class
/filter

filter-mapping
filter-nameapp/filter-name
url-pattern/*/url-pattern
/filter-mapping

/web-app

Thanks in advance
Tony Nelson
Starpoint Solutions
  


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Hibernate Sessions

2011-06-10 Thread Tony Nelson

On Jun 10, 2011, at 10:47 AM, Tony Nelson wrote:

 Hi all,
 
 I'm in the process of rebuilding an app that was done in Tap3 (indeed!) in 
 Tap5.  It's a small app, maybe a dozen pages used by my internal staff.  This 
 is in preparation for rebuilding the entire front of a much larger app.  But 
 that's a story for another day.
 
 Because I want to learn all the new Tap5 goodness, I started with an new 
 project built w/ the maven archetype.  I copied over my DB classes and added 
 the Spring dependencies I needed, and wrote a test case to make sure I could 
 read and write from my dev (h2) database.
 
 Then I created a very small page that displays a few rows from the DB in a 
 table.  The service method is trivial:
 
@Log
public ListOffice getOffices() {
return officeDao.getAllOffices(); 
}
 
 I fired up Jetty, and opened the page.  I really expected to get an exception 
 saying that I don't have a database session because I purposely did not 
 include the OpenSessionInView filter that I'm familiar with.  In addition I 
 didn't include the tapestry-hibernate jars because I'm not sure if it's 
 better to have Tap of Spring handle opening and closing the sessions.
 
 I was very surprised when the page actually rendered a result from the 
 database.  I'm still not clear where the session is coming from, but that is 
 actually my problem.  I can reload my tiny test page 8 times.  On the 9th 
 time, I see:
 
 [582385532@qtp-918884489-5] DEBUG com.starpoint.helpdesk.pages.Offices  - 
 [ENTER] getOffices()
 
 And the browser spins.  I can open the H2 DB in the H2 admin console and 
 issue queries against it, so the H2 instance is fine.
 
 Obviously I'm either out of sessions or connection pool slots.  My goal is to 
 be able to use the Spring @Transactional annotation because in the larger app 
 rewrite I have several dozen business layer Spring managed beans that depend 
 on it.
 
 I have tried adding Springs OpenSessionInViewFilter, and I've tried adding a 
 dependency on tapestry-hibernate-core.  Neither of these solutions have 
 helped.
 
 Can anyone offer any suggestions as to where the session is actually coming 
 from so that I can try to figure out how to get the session closed or 
 released?
 
 I have Spring configured like this:
 
 ?xml version=1.0 encoding=UTF-8?
 beans xmlns=http://www.springframework.org/schema/beans;
   xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
   xmlns:context=http://www.springframework.org/schema/context;
   xsi:schemaLocation=http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd;
default-autowire=byName 
 
bean id=dataSource class=org.apache.commons.dbcp.BasicDataSource
property name=driverClassName value=${dataSource.driverClass} /
property name=username value=${dataSource.user} /
property name=password value=${dataSource.password} /
property name=url value=${dataSource.jdbcURL} /
/bean
 
!-- Hibernate session factory --
bean id=sessionFactory
  
 class=org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
property name=dataSource ref=dataSource/
property name=configLocation value=classpath:/hibernate.cfg.xml/
/bean
 
!-- Hibernate transaction manager --
bean id=transactionManager
  
 class=org.springframework.orm.hibernate3.HibernateTransactionManager
property name=sessionFactory ref=sessionFactory/
/bean
 
 
context:component-scan base-package=com.starpoint.helpdesk.dao /
context:annotation-config/
 
 /beans
 
 and my web.xml is simply:
 
 ?xml version=1.0 encoding=UTF-8?
 !DOCTYPE web-app
PUBLIC -//Sun Microsystems, Inc.//DTD Web Application 2.3//EN
http://java.sun.com/dtd/web-app_2_3.dtd;
 web-app
display-nameStarpoint Help Desk Tapestry 5 Application/display-name
 
context-param
!--
The only significant configuration for Tapestry 5, this informs 
 Tapestry
of where to look for pages, components and mixins.
--
param-nametapestry.app-package/param-name
param-valuecom.starpoint.helpdesk/param-value
/context-param
 
context-param
param-namecontextConfigLocation/param-name
param-valueclasspath:/applicationContext.xml/param-value
/context-param
 
filter
filter-nameapp/filter-name

 filter-classorg.apache.tapestry5.spring.TapestrySpringFilter/filter-class
/filter
 
filter-mapping
filter-nameapp/filter-name
url-pattern/*/url-pattern
/filter-mapping
 
 /web-app
 

I turned on debug logging and get this when the request hangs:

[1828511825@qtp-68769219-3] DEBUG com.starpoint.helpdesk.pages.Offices  - 
[ENTER] getOffices()
[1828511825@qtp-68769219-3] 

Re: Tapestry Hibernate Sessions

2011-06-10 Thread Thiago H. de Paula Figueiredo
On Fri, 10 Jun 2011 12:12:01 -0300, Tony Nelson tnel...@starpoint.com  
wrote:



So maybe I should have sent this question to the Spring list?


If you're not using Tapestry-Hibernate this question went to the wrong  
list. :)


All the same, does anyone have any insight into what I may have done  
wrong?


Is your OpenSessionInViewFilter declared before the TapestryFilter? It  
should.


--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor

Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Hibernate Sessions

2011-06-10 Thread Thiago H. de Paula Figueiredo
On Fri, 10 Jun 2011 11:47:58 -0300, Tony Nelson tnel...@starpoint.com  
wrote:



Hi all,


Hi!

I fired up Jetty, and opened the page.  I really expected to get an  
exception saying that I don't have a database session because I  
purposely did not include the OpenSessionInView filter that I'm familiar  
with.  In addition I didn't include the tapestry-hibernate jars because  
I'm not sure if it's better to have Tap of Spring handle opening and  
closing the sessions.


You can't use Tapestry-Hibernate and Spring-Hibernate at the same time, as  
both manage Hibernate sessions and instantiates SessionFactory's (through  
the Configuration class, of course). And adding Tapestry-Hibernate to the  
classpath means it's being used.


--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor

Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Tapestry Hibernate Sessions

2011-06-10 Thread Tony Nelson

On Jun 10, 2011, at 11:32 AM, Thiago H. de Paula Figueiredo wrote:

 On Fri, 10 Jun 2011 12:12:01 -0300, Tony Nelson tnel...@starpoint.com wrote:
 
 So maybe I should have sent this question to the Spring list?
 
 If you're not using Tapestry-Hibernate this question went to the wrong list. 
 :)
 

Indeed it was a Spring related issue.  Doing some more searching I found that 
Spring requires @Transactional now, and I had only added my data access tier.  
Creating a quick business tier and marking the interface @Transactional solved 
the problem.  For anyone that may find this in [insert favorite search engine] 
later:

My interface for my business class:

package com.starpoint.helpdesk.business;

import com.starpoint.helpdesk.domain.Office;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true)
public interface OfficeLogic {

ListOffice getAllOffices();
}

The page was of course updated to call this method instead of the DAO directly. 
 The updated applicationContext.xml is:

?xml version=1.0 encoding=UTF-8?
beans xmlns=http://www.springframework.org/schema/beans;
   xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
   xmlns:context=http://www.springframework.org/schema/context;
   xmlns:tx=http://www.springframework.org/schema/tx;
   xsi:schemaLocation=http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context.xsd
   http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd;
default-autowire=byName 

bean id=dataSource class=org.apache.commons.dbcp.BasicDataSource 
destroy-method=close
property name=driverClassName value=${dataSource.driverClass} /
property name=username value=${dataSource.user} /
property name=password value=${dataSource.password} /
property name=url value=${dataSource.jdbcURL} /
/bean

!-- Hibernate session factory --
bean id=sessionFactory
  class=org.springframework.orm.hibernate3.LocalSessionFactoryBean
property name=dataSource ref=dataSource/
property name=configLocation value=classpath:/hibernate.cfg.xml/
/bean

!-- Hibernate transaction manager --
bean id=transactionManager
  
class=org.springframework.orm.hibernate3.HibernateTransactionManager
property name=sessionFactory ref=sessionFactory/
/bean


context:component-scan base-package=com.starpoint.helpdesk.dao /
context:component-scan base-package=com.starpoint.helpdesk.business /

context:annotation-config/

tx:annotation-driven transaction-manager=transactionManager /

/beans