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 wrote:

> 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"  >
> To: "Struts Users Mailing List" ; <
> 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:
>>
>> > class="org.springframework.orm.hibernate.HibernateTransactionManager">
>> 
>> 
>>
>> 
>>
>> 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


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" 
To: "Struts Users Mailing List" ; 


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:







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 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 wrote:

> 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:
>
>
>  class="org.springframework.orm.hibernate.HibernateTransactionManager">
>
>
>
>
>
> 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 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:







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 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



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 List 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*
*
*




..




.


org.hibernate.dialect.Oracle10gDialect
true






*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());
}

}