Query Logical Hibernate

Asked

Viewed 40 times

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 on Hibernate in a Boolean method and return:

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

I don’t know how to implement this in the above method.

  • I believe in your query you need to put like this: select * from usuario where superusuario = true and usuarioativo = true

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.