Skip to content
Anjunar/ DOCS

Locales and queries

Load, edit, filter and page in a fixed Session locale, with fallback resolved per field.

Locale

Bind language to the Session

The content locale is immutable for a Session. Use a new Session for another language and ordinary managed properties for active-locale writes.

A transactional title edit

Load in German, edit the normal String field, then commit. Roll back failures and always close the Session.

scala
val session = HibernateI18n.openSession(factory, "de") try val tx = session.beginTransaction() try val page = session.find(classOf[Page], pageId) page.title = "Hallo" tx.commit() catch case error: Throwable => if tx.isActive then tx.rollback() throw error finally session.close()
exact locale → language → fallbackLocale → defaultLocale
The lookup is per field. A missing title can fall back while another field still uses the active locale.
Removing an override

Setting a translated property to null clears its active-locale override. Refresh or a new Session reads the fallback; clearing the last field removes the empty translation row.

Queries

Filter and page by translated values

HQL and Criteria operate on the locale-resolved property. Ordering and paging therefore use the same translated value as loading.

A localized HQL page

Run inside a localized Session and transaction. The active language and fallback determine the predicate and order.

scala
val pages = session.createQuery( "from Page p where p.title like :prefix order by p.title", classOf[Page]) .setParameter("prefix", "H%") .setFirstResult(0) .setMaxResults(10) .getResultList