Foros del Web » Programación para mayores de 30 ;) » Java »

Consulta hibernate

Estas en el tema de Consulta hibernate en el foro de Java en Foros del Web. Hola, tengo la sgute consulta: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código PHP: Ver original List < TextoCatalogo > result = ( List < TextoCatalogo > ) session . ...
  #1 (permalink)  
Antiguo 05/07/2011, 08:17
 
Fecha de Ingreso: diciembre-2010
Mensajes: 459
Antigüedad: 13 años, 4 meses
Puntos: 21
Consulta hibernate

Hola, tengo la sgute consulta:


Código PHP:
Ver original
  1. List<TextoCatalogo> result = (List<TextoCatalogo>) session.createQuery("from TextoCatalogo where clave_catalo='" + clave + "' and ididioma=1").list();

Y eso me devuelve la lista

pero como puedo hacer para realizar esta consulta con hibernate:

select max(idtextocat) from TextoCatalogo

Gracias

Saludos
  #2 (permalink)  
Antiguo 06/07/2011, 11:22
 
Fecha de Ingreso: junio-2011
Mensajes: 39
Antigüedad: 12 años, 10 meses
Puntos: 16
Respuesta: Consulta hibernate

Usando la clases Criteria y Projection

Código PHP:
return ((Number)session.createCriteria(TextoCatalogo.class)
    .
setProjectionProjections.projectionList()
        .
addProjections.max("idtextocat") )
    ).
uniqueResult()).intValue(); 
Usando HQL

Código PHP:
String hql "select max(idtextocat) from TextoCatalogo";
Query query session.createQuery(hql);
return ((
Numberquery.uniqueResult()).intValue(); 
Espero sea de ayuda.
__________________
Saludos desde Colombia.
http://labs.distrit.co
  #3 (permalink)  
Antiguo 06/07/2011, 11:24
 
Fecha de Ingreso: junio-2011
Mensajes: 16
Antigüedad: 12 años, 10 meses
Puntos: 2
Respuesta: Consulta hibernate

Strgin sql= ("Selet select max(idtextocat) from TextoCatalogo where clave_catalo='" + clave + "' and ididioma=1").
solo que ahy nadamas tendrias un resultado
List Listatemporal = sessionHib.createQuery(SQL).list();
no se que desees hacer?
  #4 (permalink)  
Antiguo 07/07/2011, 02:01
 
Fecha de Ingreso: diciembre-2010
Mensajes: 459
Antigüedad: 13 años, 4 meses
Puntos: 21
Respuesta: Consulta hibernate

Al final realize esto pero gracias por vuestra ayuda

String consulta="select max(idtextocat) from TextoCatalogo";
List result = session.createQuery(consulta).list();
String max=result.get(0).toString();
int maxId=Integer.parseInt(max)+1;

Pero este trozo e codigo no me funciona:


return ((Number) query.uniqueResult()).intValue();

no me deja hacer el int value
  #5 (permalink)  
Antiguo 07/07/2011, 11:11
 
Fecha de Ingreso: junio-2011
Mensajes: 16
Antigüedad: 12 años, 10 meses
Puntos: 2
Respuesta: Consulta hibernate

Long numrecords=new Long(0);
Iterator itempIterator=Listatemporal.iterator();
try{
while(itempIterator.hasNext()){
Object Objetos=(Object)itempIterator.next();
numrecords=(Long)Objetos;
}
}catch (NullPointerException ex){
}
System.out.println("La Consulta se genero Correctamente"+numrecords.intValue());
agrega esto despues de que generes tu lista y ve si te sirve

Etiquetas: hibernate
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 2 personas




La zona horaria es GMT -6. Ahora son las 14:27.