What is the Hibernate equivalent of "select 1 from DUAL"?

What is the minimum sleep request? Is there an equivalent to "choose 1 from DUAL" for Hibernate?

I am writing a healthcheck function and would like to execute a minimal query, but use HQL to keep the code portable (as opposed to using my own query).

+5
source share
5 answers

dialects of hibernation - this is what is translated into various databases, and there is no support for "health checks" or "checks" on dialects. This usually happens with a pool of connections, rather than sleeping. See, for example, DBCP Validation Validation Property .

+4
source

SQL is select 1 from DUAL;not a good health check, the only thing you see is the server response, which does not mean that the data itself is healthy. But if you want to ask such a question, just create your own data object that mimics DUAL, and you control the object, and you will remain common to any DBMS.

Sort of

@Entity
@Table(name="myDual")
public class MyDual implements Serializable {

  @Id
  @Column(name = "id")
  Integer id;

  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

}

CacheMode.IGNORE CacheMode.REFRESH . , ...

+4

SQL- . - session.createSQLQuery("Select 1 from dual").uniqueResult();

,

session.createQuery("select 1 from existingTable").setMaxResults(1).uniqueResult();
+3

Hmm, , 1 dual , . ANSI information_schema , , DB, , , .

+1

DUAL hibernate

session.createSQLQuery("SELECT 1 from DUAL") 

session.createQuery("SELECT 1 from DUAL").
+1

All Articles