-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Ajax request at current session
PostPosted: Thu Jun 03, 2010 2:02 pm 
Newbie

Joined: Wed Mar 03, 2010 6:27 am
Posts: 11
Hi all,
In my web application I got a problem, If oneone help, I ll be very pleasent.
I developed my application using hibernate (at all requests I used a new openSession() and after the request I closed session). Because I open and close sessiın for every request, there was no error when I render changes.
But then I changed I application with session.getCurrentSession(). Now after I make a change at any object,It doesnt affect at render when I requset an ajax call.
I got there is no row with selected object.
I give two example and can you tell me where shall I make changes?
Code:

    public Media addMessage(String filename, String content, Long uid, Long recipientId) {
        Media med = null;
        Transaction tx = null;
        try {
            session = HibernateUtil.getCurrentSession();
            if (!session.isConnected()) {
                session = HibernateUtil.getSession();
            }
            tx = session.beginTransaction();
            User user = (User) session.load(User.class, uid);
            User recipient = (User) session.load(User.class, recipientId);
            med = new Media(filename, content, user, recipient);
            session.save(med);
            tx.commit(); // Automatically closes session
            session.flush();
        } catch (Exception e) {           
            return null;
        }
        return med;
    }

First, I add e text message to db,

Code:
// used for refreshing
    public Media getMessage(String filename, Long uid) {
        Media m = null;
        try {
            session = HibernateUtil.getCurrentSession();
            if (!session.isConnected()) {
                session = HibernateUtil.getSession();
            }
            Query q = session.createQuery("from Media m where (m.fileName = :var1 and m.user = :var2)");
            q.setString("var1", filename);
            q.setLong("var2", uid);
            List result = q.list();
            if(result.size() > 0){
                m = (Media) result.get(0);
            }
                session.flush();

        } catch (HibernateException ex) {

            return null;
        }
        return m;
    }   

then I use this method for render with ajax.
But I got exception here.
How Can I fix it?
Thanks...


Top
 Profile  
 
 Post subject: Re: Ajax request at current session
PostPosted: Tue Jun 08, 2010 5:06 am 
Newbie

Joined: Wed Mar 03, 2010 6:27 am
Posts: 11
Any suggestion, solution?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.