-->
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.  [ 4 posts ] 
Author Message
 Post subject: hibernate and ajax
PostPosted: Tue Mar 18, 2008 11:40 am 
Newbie

Joined: Tue Mar 18, 2008 10:49 am
Posts: 4
Location: chile
I am using Ajax, specifically prototype.js. Upon executing the instruction session.close (), breaks the execption Session was already closed.
The version 3.2 is hibernate
Without using ajax all good spirit.

Does anyone know where I need to do?

Sincerely,
german salinas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 11:43 am 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
Please post the code for us to help you.

I'm also using prototype but using DWR to handle my ajax hibernate CRUD calls.


Top
 Profile  
 
 Post subject: hibernate and ajax
PostPosted: Tue Mar 18, 2008 11:58 am 
Newbie

Joined: Tue Mar 18, 2008 10:49 am
Posts: 4
Location: chile
pooter8d wrote:
Please post the code for us to help you.

I'm also using prototype but using DWR to handle my ajax hibernate CRUD calls.


--------------------------------
Hi,

this is jsp with call ajax

function ListaHelp()
{
document.listapreciosForm.correlativo.value=document.listapreciosForm.buscarlista.value;
url = 'http://127.0.0.1:8080/TransFrontera/servlet/AdapterHTTP?ACTION_NAME=precioslista&correlativo='+document.listapreciosForm.correlativo.value;
pars = '';
var myAjax = new Ajax.Request(
url,
{
method: 'get',
parameters: pars,
onComplete: mostrarTexto
}
);
}

function mostrarTexto(resp)
{

if (resp.readyState == 4) {

var xml = resp.responseXML;
var lista = xml.getElementsByTagName('LISTA')[0];
var fecha = xml.getElementsByTagName('FECHA')[0];
var tipolista = xml.getElementsByTagName('TIPO_LISTA')[0];
var destino = xml.getElementsByTagName('DESTINO')[0];
var tipocliente = xml.getElementsByTagName('TIPO_CLIENTE')[0];
var detalle = xml.documentElement.getElementsByTagName("DETALLE");
document.listapreciosForm.lista.value=lista.firstChild.data;
document.listapreciosForm.fecha.value=fecha.firstChild.data;

for(i=0;i<document.listapreciosForm.tipo_lista.length;i++)
if(document.listapreciosForm.tipo_lista.options[i].value == tipolista.firstChild.data)
document.listapreciosForm.tipo_lista.selectedIndex=i;

for(i=0;i<document.listapreciosForm.buscardestino.length;i++)
if(document.listapreciosForm.buscardestino.options[i].text == destino.firstChild.data)
document.listapreciosForm.buscardestino.selectedIndex=i;

for(i=0;i<document.listapreciosForm.buscartipo.length;i++)
if(document.listapreciosForm.buscartipo.options[i].text == tipocliente.firstChild.data)
document.listapreciosForm.buscartipo.selectedIndex=i;

for(i=0;i<document.listapreciosForm.orden.length;i++)
{
document.listapreciosForm.orden[i].value=0;
document.listapreciosForm.precio[i].value=0;
document.listapreciosForm.descto_por[i].value=0;
document.listapreciosForm.descto_pesos[i].value=0;
document.listapreciosForm.kilos[i].value=0;
document.listapreciosForm.volumen[i].value=0;
}
for(i=0;i<xml.documentElement.getElementsByTagName("DETALLE").length;i++)
{
document.listapreciosForm.orden[i].value=detalle[i].getAttribute("orden");
document.listapreciosForm.precio[i].value=detalle[i].getAttribute("precio");
document.listapreciosForm.descto_por[i].value=detalle[i].getAttribute("despor");
document.listapreciosForm.descto_pesos[i].value=detalle[i].getAttribute("despes");
document.listapreciosForm.kilos[i].value=detalle[i].getAttribute("kilos");
document.listapreciosForm.volumen[i].value=detalle[i].getAttribute("volumen");
}

}
}
</script>


--------------------
this is a servlet to response

public class Listadoprecios extends AbstractAction {


static Session session = null;
public Listadoprecios(){

}
public void service(SourceBean request, SourceBean response) throws Exception {

try
{
/* String primero = (String)request.getAttribute("correlativo");
Integer correlativo = Integer.parseInt(primero.trim());

session=HibernateUtil.getSessionFactory().getCurrentSession();
if(session!=null && !session.isOpen())
session=null;
if(session==null)

session=HibernateUtil.getSessionFactory().openSession();

session.beginTransaction();

Tfr_lista_precios lpr=(Tfr_lista_precios) session.get(Tfr_lista_precios.class,correlativo);

String consulta = "FROM Det_Tfr_lista_precios as P WHERE P.lista_precios.id="+correlativo;

List result = session.createQuery(consulta).list(); */

response.setName("LISTA_PRECIOS");

SourceBean lista = new SourceBean(response);
SourceBean fecha = new SourceBean(response);
SourceBean destino = new SourceBean(response);
SourceBean tipo_cliente = new SourceBean(response);
SourceBean tipo_lista = new SourceBean(response);
SourceBean detalle = new SourceBean(response);

lista.setName("LISTA");
lista.setCharacters("URTRTRURURUR");
response.setAttribute(lista);

fecha.setName("FECHA");
fecha.setCharacters("20/11/2008");
response.setAttribute(fecha);

destino.setName("DESTINO");
destino.setCharacters("SANTIAGO - TEMUCO");
response.setAttribute(destino);

tipo_cliente.setName("TIPO_CLIENTE");
tipo_cliente.setCharacters("FERRETERIA");
response.setAttribute(tipo_cliente);

tipo_lista.setName("TIPO_LISTA");
tipo_lista.setCharacters("PESO");
response.setAttribute(tipo_lista);


for (int i = 0; i<7; i++) {


SourceBean detalle_lista =new SourceBean(detalle);

detalle_lista.setName("DETALLE");
detalle_lista.setAttribute("orden",i);
detalle_lista.setAttribute("precio",i*100);
detalle_lista.setAttribute("despor",0);
detalle_lista.setAttribute("despes",i*10);
detalle_lista.setAttribute("kilos",i*10);
detalle_lista.setAttribute("volumen",0);

response.setAttribute(detalle_lista);

}


/* lista.setName("LISTA");
lista.setCharacters(lpr.getLista());
response.setAttribute(lista);

fecha.setName("FECHA");
SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
fecha.setCharacters(formato.format(lpr.getFecha()));
response.setAttribute(fecha);

destino.setName("DESTINO");
destino.setCharacters(lpr.getDestino().getDestino());
response.setAttribute(destino);

tipo_cliente.setName("TIPO_CLIENTE");
tipo_cliente.setCharacters(lpr.getTipoclt().getTipo_cliente());
response.setAttribute(tipo_cliente);

tipo_lista.setName("TIPO_LISTA");
tipo_lista.setCharacters(lpr.getTipo_lista());
response.setAttribute(tipo_lista);


for (int i = 0; i<result.size(); i++) {

Det_Tfr_lista_precios dlpr = (Det_Tfr_lista_precios) result.get(i);

SourceBean detalle_lista =new SourceBean(detalle);

detalle_lista.setName("DETALLE");
detalle_lista.setAttribute("orden",dlpr.getOrden());
detalle_lista.setAttribute("precio",dlpr.getPrecio());
detalle_lista.setAttribute("despor",dlpr.getDescto_por());
detalle_lista.setAttribute("despes",dlpr.getDescto_pesos());
detalle_lista.setAttribute("kilos",dlpr.getKilos());
detalle_lista.setAttribute("volumen",dlpr.getVolumen());

response.setAttribute(detalle_lista);

}

session.getTransaction().commit();
session.close(); */

}catch (HibernateException ex) {
TracerSingleton.log("Transfrontera", TracerSingleton.CRITICAL,"Error Inicio Listado Lista:", ex);
throw new InfrastructureException(ex);
}
}
}

---------------------------------
this is a servlet updated in BD

public static boolean update(String lista,String tipo_lista,Date fecha,Integer destino,Integer tipoclt,List lista_orden,List lista_precio,List lista_dctopor,List lista_dctopes,List lista_kilos,List lista_volumen,Integer correlativo)
{
Session session = null;
try
{
session=HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Tfr_Destino dst=(Tfr_Destino) session.get(Tfr_Destino.class,destino);
Tfr_Tipoclt clt=(Tfr_Tipoclt) session.get(Tfr_Tipoclt.class,tipoclt);
Tfr_lista_precios lpr=(Tfr_lista_precios) session.get(Tfr_lista_precios.class,correlativo);
lpr.setLista(lista);
lpr.setFecha(fecha);
lpr.setTipo_lista(tipo_lista);
lpr.setDestino(dst);
lpr.setTipoclt(clt);
session.update(lpr);
String consulta = "FROM Det_Tfr_lista_precios as P WHERE P.lista_precios.id="+correlativo;
List result = session.createQuery(consulta).list();
for(int i=0;i<result.size();i++){
Det_Tfr_lista_precios dlpr = (Det_Tfr_lista_precios) result.get(i);
session.delete(dlpr);
}
for(int i=0;i<lista_orden.size();i++){
if(Integer.parseInt((String)lista_orden.get(i))>0){
Det_Tfr_lista_precios dlpr = new Det_Tfr_lista_precios();
dlpr.setOrden(Integer.parseInt((String)lista_orden.get(i)));
dlpr.setPrecio(Float.parseFloat((String)lista_precio.get(i)));
dlpr.setDescto_por(Float.parseFloat((String)lista_dctopor.get(i)));
dlpr.setDescto_pesos(Float.parseFloat((String)lista_dctopes.get(i)));
dlpr.setKilos(Float.parseFloat((String)lista_kilos.get(i)));
dlpr.setVolumen(Float.parseFloat((String)lista_volumen.get(i)));
dlpr.setLista_precios(lpr);
session.save(dlpr);

}
}

session.getTransaction().commit();
session.close();

}
catch (HibernateException ex){
TracerSingleton.log("Transfrontera", TracerSingleton.CRITICAL,"ListapreciosDao:update:", ex);
return false;
}
return true;
}


many thank you,

german salinas


Top
 Profile  
 
 Post subject: Re: hibernate and ajax
PostPosted: Tue Apr 01, 2008 9:16 am 
Newbie

Joined: Tue Mar 18, 2008 10:49 am
Posts: 4
Location: chile
Hi,

I solved the problem. This is very simpled. All action with hibernate, keep up inside the call Ajax.


Best regard,
German


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