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