Hibernate Notes

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.

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

(see hibernate documentation for more details)