Hi Abhi,
I believe you are out of luck there, you'll need access to hibernate session.
There are few things you can do, e.g.:
- do a left-fetch join of all collections taht you are going to access
(yup, painfull, but that's what we did in our last EJB3 project)
- do a explicit call to your collections so hibernate loads them e.g. foo.getKids()
- use Hibernate.initialize(foo.getKids());
- load eagerly(!)

there are probably more tricks..









On 11/28/2008 10:39 AM, Abhi wrote:
I went ahead and configured hibernate and spring :).

I have a data access layer where my transactions start and end. When I run my action beans from a main method and try to iterate over a lazily loaded collection I get an exception as the Session is closed by then. When running inside the container I know that I can solve this by using the open session in view filter. Is there a way to resolve this problem when running stand alone from an action bean?

On Tue, Nov 18, 2008 at 7:57 PM, Aaron Porter <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    It doesn't sound like he's using Stripersist but if he is and for
    you Alex, you can use Stripersist outside of Stripes by calling
    Stripersist.init(url) with url pointing to persistence.xml. Then
    call Stripersist.requestInit() before using it in every thread and
    call Stripersist.requestComplete() after. The requestInit() call
    should be in a try block with requestComplete() in a finally block
    just to make sure things get cleaned up.

    Aaron

    Alex Turner wrote:
    Hmm... that's a good question.  I guess the best person to answer
    that would be the guy who wrote Stripersist, personally I'm not
    sure, but I would sure like to know myself!

    Alex

    On Sun, Nov 16, 2008 at 2:42 AM, Abhi <[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>> wrote:

        Thanks for that Alex. I have a question regarding the usage
        of Spring and Hibernate with Stripes.

        If I use Spring, Hibernate and Stripes stack, can I test DB
        persistence stand alone (As in from a main method)? I have
        used struts(1.2), Spring and Hibernate stack before and there
        was no way (or maybe I did not know of one) I could test
        stand alone.

        On Sat, Nov 15, 2008 at 3:54 PM, Abhi
        <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

            I have to acess a Database Connection object in my action
            bean. I am using plain old vanilla JDBC(no Spring and
            Hibernate). I am setting the DataSource object in
            ServletContext on application initialization and using
            this DataSource object to get a DB Connection object
            whenever I want.

            One approach that I can take is to get the Connection
            object directly from the ServletContext in my method and
            use it. But the problem with this approach is that I
            can't test my action bean stand alone (as the Connection
            object is taken from the ServletContext).

            To over come this I have provided a setter and getter for
            Connection in my action bean and I use an Interceptor to
            inject the Connection object into my bean before
            HandlerResolution life cycle stage. The advantage of this
            is, now I can test my bean stand alone by setting my own
            Connection object and when it runs inside a servlet
            container Stripes does the injection for me. To close the
            connection also I am using an intercptor that closes the
            connection after ResolutionExecution life cycle stage.

            Is my approach correct or is there a better way to
            achieve what I want?

-- Cheers,
            Abhi




-- Cheers,
        Abhi

        
-------------------------------------------------------------------------
        This SF.Net email is sponsored by the Moblin Your Move
        Developer's challenge
        Build the coolest Linux based applications with Moblin SDK &
        win great prizes
        Grand prize is a trip for two to an Open Source event
        anywhere in the world
        http://moblin-contest.org/redirect.php?banner_id=100&url=/
        <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
        _______________________________________________
        Stripes-users mailing list
        [email protected]
        <mailto:[email protected]>
        https://lists.sourceforge.net/lists/listinfo/stripes-users


    ------------------------------------------------------------------------
    -------------------------------------------------------------------------
    This SF.Net email is sponsored by the Moblin Your Move
    Developer's challenge Build the coolest Linux based applications
    with Moblin SDK & win great prizes Grand prize is a trip for two
    to an Open Source event anywhere in the world
    http://moblin-contest.org/redirect.php?banner_id=100&url=/
    <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
    ------------------------------------------------------------------------

    _______________________________________________
    Stripes-users mailing list
    [email protected] 
<mailto:[email protected]>
    https://lists.sourceforge.net/lists/listinfo/stripes-users


    -------------------------------------------------------------------------
    This SF.Net email is sponsored by the Moblin Your Move Developer's
    challenge
    Build the coolest Linux based applications with Moblin SDK & win
    great prizes
    Grand prize is a trip for two to an Open Source event anywhere in
    the world
    http://moblin-contest.org/redirect.php?banner_id=100&url=/
    <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
    _______________________________________________
    Stripes-users mailing list
    [email protected]
    <mailto:[email protected]>
    https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Cheers,
Abhi
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to