I'm trying to retrieve data from database through hibernate. But i'm getting "org.hibernate.TransactionException : nested transactions not supported" exception when i refresh my jsp page. Some times i'm able to get the result but some times i'm getting above exception. I'm using beginTransaction() method only one time in the code. But still getting the exception. What might be the root cause.
My code is :
StringBuilder sb = new StringBuilder();
sb.append("{").append(STATUS).append(OK).append(", ").append(RESULTS);
sb.append("[");
if(session == null){
return getErrorMsgJson("Failed to get DB Session");
}
try {
session.beginTransaction();
ListIterator iterator3 = session.createSQLQuery(sqlStr).list().listIterator();
int t=0;
while(iterator3.hasNext()){
Object obj;
Object obj3[]=null;
if((obj=iterator3.next()) instanceof BigInteger){
sb.append("\"");
sb.append(obj.toString());
sb.append("\"");
break;
}
else{
obj3 = (Object[])iterator3.previous();
for(int i=0;i<obj3.length;i++){
sb.append("\"");
sb.append(obj3[i].toString());
sb.append("\"");
if(t<obj3.length){
sb.append(",");
}
}
}
iterator3.next();
t++;
}
//session.getTransaction().commit();
sb.append("] }");
return sb.toString();
}
catch (Exception e) {
//Log.logErr(Logc.JS, Logc.JS_INTERNAL_ERR, "Exception while getting DB Connection");
//out.println("Exception while getting DB Connection");
//return getErrorMsgJson(e.getClass().getName()+" : "+e.getMessage());
//return getErrorMsgJson(e.getClass()+" "+e.getMessage());
//e.printStackTrace();
return getErrorMsgJson(e.getClass()+" : "+e.getMessage());
}
Thanks in advance.