Query hibernate logic

0
public boolean minimoUmSuperUsuario(Usuario usuario, Session sessionExterna) throws HibernateException {
    Criteria crit = sessionExterna.createCriteria(Usuario.class);

    return (Long) crit.uniqueResult() > 0;
}

I need to do the following task:

select * from usuario where superusuario and usuarioativo = true

Make this select in hibernate in a boolean method and return:

if quantide de super usuario e ativo == 1 retornar true 
else false.

I do not know how to implement this in the above method.

    
asked by anonymous 23.08.2017 / 15:11

1 answer

0

If you want to use Hibernate Criteria:

public boolean minimoUmSuperUsuario(Usuario usuario, Session sessionExterna) throws HibernateException {
  Criteria crit = sessionExterna.createCriteria(Usuario.class);
  crit.add(Restrictions.eq("ativo",true));

  return (Long) crit.uniqueResult() > 0;
}

For more details, see Hibernate_User_Guide .

    
25.08.2017 / 06:22