Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: moved from archive to documentation space

Hibernate is an open-source object-relational mapping tool. We are using hibernate in OpenMRS to perform the majority of the low-level dirty work of communicating with the database. You can read more about hibernate at their website.

Using SQL directly

The following code shows how to inject raw SQL and fetch a string from the database.

Code Block
String pwd = (String)session.createSQLQuery("select password from users where username = ?")
  .addScalar("password", Hibernate.STRING)
  .setString(0, "admin")
  .uniqueResult();

(see hibernate documentation for more details)