-->
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.  [ 3 posts ] 
Author Message
 Post subject: Don't want to update the value in the database
PostPosted: Wed May 11, 2011 3:32 am 
Newbie

Joined: Wed May 11, 2011 3:12 am
Posts: 2
Hi,

I am using the hibernate for the first time.
My query is :

I am getting a value1 from a user and based on that value1 i am getting another value2 from the database by using first query.
Now based on value2 i am firing another query in the databse and getting the record list (value2 is the attribute of the bean class which i am getting in this list).
Now before showing it in the jsp, i need to map the previous value i.e. value1 to value2 so that user doesn't see the changed value and get confused.

When i am using the setter method of value2 to update it to value1, it is trying to update the value in the database which is undesirable.

Is there any way that i can restrict hibernate not to update the value in the database but at the same time i can set the bean attribute to be displayed to the user.

Code:
String SQL_QUERY = "Select value2 from table1 tbl1 where tbl1.column1=:id";
        Query query = session.createQuery(SQL_QUERY);
        query.setString("id", value1);

        //value1 is from the user

        for (Iterator it = query.iterate(); it.hasNext();) {
            Id2=(String)it.next();
        }

        //Criteria Query Example
        Criteria crit = session.createCriteria(Table2.class);
        crit.add(Restrictions.like("Id", "%" + Id2 + "%"));

        //Fetch the result from database
        List list = crit.list();
        for(int i=0;i<tranList.size();i++) {
           Table2 tbl2=(Table2)list.get(i);

           tbl2.setId2(value1); //here it it trying to update database which i don't want, i want only bean attribute to be changed
        }

        ActionContext.getContext().getSession().put("result", list);


Kindly suggest.

Thanks,
Aavesh


Top
 Profile  
 
 Post subject: Re: Don't want to update the value in the database
PostPosted: Thu May 12, 2011 2:34 am 
Newbie

Joined: Thu May 12, 2011 2:25 am
Posts: 1
Hi Aavesh,

Sorry, but the code snippet is not very clear since it doesn't provide information as to when you are opening and closing session and transactions.

I assume you are closing your session after this code snippet.

Please try updating your bean property after releasing your current session.
That way Hibernate will not be in effect and your bean updated values are preserved.

Please let me know if it works.

Regards,

Anshuman Chakraborty


Top
 Profile  
 
 Post subject: Re: Don't want to update the value in the database
PostPosted: Mon May 16, 2011 5:48 am 
Newbie

Joined: Wed May 11, 2011 3:12 am
Posts: 2
Thaks Anshuman.Thanks very much.

Actually i tried as per your suggestions and it worked.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.