Re: struts2+hibernate+spring - lazyInitaializationException

2010-07-19 Thread Lukasz Lenart
Hi,

I really don't see how Struts2 can messed it up. Would you try to
write a unit test to check that?


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
Kapituła Javarsovia 2010 http://javarsovia.pl

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



Re: struts2+hibernate+spring - lazyInitaializationException

2010-07-19 Thread Brian Thompson
Looks to me like the session is being closed in the scope of
hibernateTemplate.get().

I don't see a transactionManager mentioned in the XML ... you could
try adding something like this in the XML configuration file:

bean id=transactionManager

class=org.springframework.orm.hibernate.HibernateTransactionManager
property name=sessionFactory ref=sessionFactory /
/bean

tx:annotation-driven transaction-manager=transactionManager /

n.b. I haven't tested the above config, so it probably won't work
as-is.  Hopefully it helps, though.

-Brian

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



Re: struts2+hibernate+spring - lazyInitaializationException

2010-07-19 Thread Greg Stasica
hi,

thanks for your replies

lukasz
i'm not sure where the problem exactly is but after my additional test i
don't think it's s2 related... i'll try to check hibernate

brian
i've done tests with your changes but to no avail... still the same problem
even when my dao implementation class has a transaction annotation i.e.

@Repository(bookBean)
@Transactional
class BookDaoImpl {.
.



On Mon, Jul 19, 2010 at 6:22 PM, Brian Thompson elephant...@gmail.comwrote:

 Looks to me like the session is being closed in the scope of
 hibernateTemplate.get().

 I don't see a transactionManager mentioned in the XML ... you could
 try adding something like this in the XML configuration file:

bean id=transactionManager

  class=org.springframework.orm.hibernate.HibernateTransactionManager
property name=sessionFactory ref=sessionFactory /
/bean

tx:annotation-driven transaction-manager=transactionManager /

 n.b. I haven't tested the above config, so it probably won't work
 as-is.  Hopefully it helps, though.

 -Brian

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




-- 
Greg Stasica


Re: struts2+hibernate+spring - lazyInitaializationException

2010-07-19 Thread Robert Taylor

Hi Greg,

I believe Brian is correct.

You need to wrap BookDao.find(...) within a transaction or use 
OpenSessionInView.
Either one of these should keep the session open when you are navigating the 
object graph
in your DAO. If you use OSIV (OpenSessionInView) filter, then you can 
navigate the

object graph in your web tier as well.

We are using both OpenSessionInView filter and a service layer which acts as 
a facade to the data layer (DAOs). The services are annotated with 
@Transactional (although for readOnly transactions this is really 
unnecessary within the OSIV scope; but they are there for consistency).


/robert
- Original Message - 
From: Brian Thompson elephant...@gmail.com
To: Struts Users Mailing List user@struts.apache.org; 
lukasz.len...@gmail.com

Sent: Monday, July 19, 2010 1:22 PM
Subject: Re: struts2+hibernate+spring - lazyInitaializationException



Looks to me like the session is being closed in the scope of
hibernateTemplate.get().

I don't see a transactionManager mentioned in the XML ... you could
try adding something like this in the XML configuration file:

bean id=transactionManager
class=org.springframework.orm.hibernate.HibernateTransactionManager
property name=sessionFactory ref=sessionFactory /
/bean

tx:annotation-driven transaction-manager=transactionManager /

n.b. I haven't tested the above config, so it probably won't work
as-is.  Hopefully it helps, though.

-Brian

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




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



Re: struts2+hibernate+spring - lazyInitaializationException

2010-07-19 Thread Greg Stasica
hi,

thanks for all your help... as it turned out the problem was in my
configuration :).. basically one of my service wasn't annotated with
@Transaction tag and as a consequence my template was closing the session ..

On Mon, Jul 19, 2010 at 8:44 PM, Robert Taylor rtay...@dtgresults.comwrote:

 Hi Greg,

 I believe Brian is correct.

 You need to wrap BookDao.find(...) within a transaction or use
 OpenSessionInView.
 Either one of these should keep the session open when you are navigating
 the object graph
 in your DAO. If you use OSIV (OpenSessionInView) filter, then you can
 navigate the
 object graph in your web tier as well.

 We are using both OpenSessionInView filter and a service layer which acts
 as a facade to the data layer (DAOs). The services are annotated with
 @Transactional (although for readOnly transactions this is really
 unnecessary within the OSIV scope; but they are there for consistency).

 /robert
 - Original Message - From: Brian Thompson elephant...@gmail.com
 
 To: Struts Users Mailing List user@struts.apache.org; 
 lukasz.len...@gmail.com
 Sent: Monday, July 19, 2010 1:22 PM
 Subject: Re: struts2+hibernate+spring - lazyInitaializationException



  Looks to me like the session is being closed in the scope of
 hibernateTemplate.get().

 I don't see a transactionManager mentioned in the XML ... you could
 try adding something like this in the XML configuration file:

 bean id=transactionManager
 class=org.springframework.orm.hibernate.HibernateTransactionManager
 property name=sessionFactory ref=sessionFactory /
 /bean

 tx:annotation-driven transaction-manager=transactionManager /

 n.b. I haven't tested the above config, so it probably won't work
 as-is.  Hopefully it helps, though.

 -Brian

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



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




-- 
Greg Stasica


struts2+hibernate+spring - lazyInitaializationException

2010-07-18 Thread Greg Stasica
hi,

i've been testing very simply scenario using aforementioned technologies but
all i get is LazyInitializationException while trying to access my entity
collection. I've included some code snippets below to make myself very
clear. I don't think there is anything wrong with the attached code as most
of the examples i found on the Internet use exactly (at least i haven't seen
any differences ) this approach. This makes me believe that somehow s2 works
differently here and causes the problem (.. perhaps it's a long shot on my
part but perhaps attaching each action to the ThreadLocal is the problem ?
Surely it's not a problem of having or not having OpenSessionInViewFilter as
the call to hibernate doesn't originate from the view layer (jsp)

*Entity*

@Entity
class Book{

  @OneToMany.
  private ListAuthor authors;
}

*DAOImpl*

class BookDaoImpl {

 public Book find(int Id)
{

 Book sv = hibernateTemplate.get(Book.class, Id);  //this line works
fine

 sv.getAuthors().size();  //this line throws LazyInitializationException


return sv;
}

@Autowired
@Qualifier(sessionFactory)
public void setSessionFactory(SessionFactory sessionFactory)
{
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
}

*spring configuration xml*
*
*
beans...
context:component-scan base-package=com.xx.service,com.xx.dao
/context:component-scan
bean class=org.apache.commons.dbcp.BasicDataSource destroy-method=close
id=dataSource
../bean

bean id=sessionFactory
class=org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
property name=dataSource ref=dataSource /
property name=annotatedClasses
list.
property name=hibernateProperties
props
prop key=hibernate.dialectorg.hibernate.dialect.Oracle10gDialect/prop
prop key=hibernate.show_sqltrue/prop
/props
/property
/bean

/beans

*BeanManager - i'm using this class in struts actions to retrieve spring
beans as i don't want to use spring object factory shipped with struts2*

public class BeanManager {
public static synchronized BeanManager getInstance() {
if(instance==null)
{
instance = new BeanManager();
}
return instance;
}

protected BeanManager()
{
URL url =
BeanManager.class.getClassLoader().getResource(applicationContext.xml);
 ctx = new FileSystemXmlApplicationContext(url.getPath());
}

}